Invalid identifier error using UNION ALL?
Can someone tell me why it gives me the error: ORA-00904: "Wait_time": invalid identifier.It must be something with the UNION ALL because it works fine if I have only one query at a time.
Thank you
Deanna
Select wait_time | ' Minutes.' | «, » || COUNTY (wait_time) under the name of "0 to 10 Min, COUNT"
Of MOTOR_ASSIST2
WHERE the wait_time BETWEEN 0 AND 10 and ((: p53_fiscal_yr IS NULL))
GOLD: p53_fiscal_yr = TO_CHAR (ADD_MONTHS (datetime, 6), "YYYY"))
OR (: p53_month IS NULL or: P53_month = TO_CHAR (DATETIME, 'MM'))
(AND (: p53_year IS NULL or: p53_year = TO_CHAR (DATETIME, 'YYYY')))
UNION ALL
Select wait_time | ' Minutes.' | «, » || COUNTY (wait_time) under the name of "11-30 Min, COUNT.
Of MOTOR_ASSIST2
where wait_time BETWEEN 11 AND 30 and ((: p53_fiscal_yr IS NULL))
GOLD: p53_fiscal_yr = TO_CHAR (ADD_MONTHS (datetime, 6), "YYYY"))
OR (: p53_month IS NULL or: P53_month = TO_CHAR (DATETIME, 'MM'))
(AND (: p53_year IS NULL or: p53_year = TO_CHAR (DATETIME, 'YYYY')))
UNION ALL
Select wait_time | ' Minutes.' | «, » || COUNTY (wait_time) under the name of "31-60 Min, COUNT.
of MOTOR_ASSIST2
where wait_time BETWEEN 31 AND 60 and ((: p53_fiscal_yr IS NULL))
GOLD: p53_fiscal_yr = TO_CHAR (ADD_MONTHS (datetime, 6), "YYYY"))
OR (: p53_month IS NULL or: P53_month = TO_CHAR (DATETIME, 'MM'))
(AND (: p53_year IS NULL or: p53_year = TO_CHAR (DATETIME, 'YYYY')))
UNION ALL
Select wait_time | ' Minutes.' | «, » || (WAIT_TIME) count as '61 Min + COUNT.
of MOTOR_ASSIST2
where wait_time BETWEEN 61 AND 1000 and ((: p53_fiscal_yr IS NULL))
GOLD: p53_fiscal_yr = TO_CHAR (ADD_MONTHS (datetime, 6), "YYYY"))
OR (: p53_month IS NULL or: P53_month = TO_CHAR (DATETIME, 'MM'))
(AND (: p53_year IS NULL or: p53_year = TO_CHAR (DATETIME, 'YYYY')))
WAIT_TIME GROUP
ORDER BY WAIT_TIME;
And if you want to be really want...
SQL> ed
Wrote file afiedt.buf
1 WITH c1 as (select row_number() over (order by sal) as rn
2 ,SAL||':'||COUNT(*) "SAL0-999"
3 from emp
4 where sal between 0 and 999
5 group by sal)
6 ,c2 as (select row_number() over (order by sal) as rn
7 ,SAL||':'||COUNT(*) "SAL1000-1999"
8 from emp
9 where sal between 1000 and 1999
10 group by sal)
11 ,c3 as (select row_number() over (order by sal) as rn
12 ,SAL||':'||COUNT(*) "SAL2000-2999"
13 from emp
14 where sal between 2000 and 2999
15 group by sal)
16 ,c4 as (select row_number() over (order by sal) as rn
17 ,SAL||':'||COUNT(*) "SAL3000-3999"
18 from emp
19 where sal between 3000 and 3999
20 group by sal)
21 ,c5 as (select row_number() over (order by sal) as rn
22 ,SAL||':'||COUNT(*) "SAL4000+"
23 from emp
24 where sal >= 4000
25 group by sal)
26 select "SAL0-999", "SAL1000-1999", "SAL2000-2999", "SAL3000-3999", "SAL4000+"
27 from c1 FULL OUTER JOIN c2 ON (c2.rn = c1.rn)
28 FULL OUTER JOIN c3 ON (c3.rn = COALESCE(c1.rn, c2.rn))
29 FULL OUTER JOIN c4 ON (c4.rn = COALESCE(c1.rn, c2.rn, c3.rn))
30 FULL OUTER JOIN c5 ON (c5.rn = COALESCE(c1.rn, c2.rn, c3.rn, c4.rn))
31* order by 1,2,3,4,5
SQL> /
SAL0-999 SAL1000-1999 SAL2000-2999 SAL3000-3999 SAL4000+
-------------- -------------- -------------- -------------- --------------
800:1 1100:1 2450:1 3000:2 5000:1
950:1 1250:2 2850:1
1300:1 2975:1
1500:1
1600:1
SQL>
Published by: BluShadow on November 7, 2008 15:47
Elimination of unnecessary case statements
Tags: Database
Similar Questions
-
Select different columns using union all
I'm trying to select all the records of two table
Select A, B, C from table1
Union of all the
Select A, B, D, E, F from table2
I get results A, B, C columns but not D, E, F.
What should I do to get all the columns in the result. as A, B, C, D, E, F
Thank you
SKHello
That's what you asked for:
select Total_Customer_Qty, NULL AS Total_Supplier_Qty, Item_number, Org,item_id from table1; union all select NULL AS Total_Customer_Qty, Total_Supplier_Qty, Item_number, Org,item_id from table2;
I hope that's what you want, too.
If not, post a small example of data (CREATE TABLE and only relevant columns, INSERT statements) for all tables and also post the results desired from these data.
Explain, using specific examples, how you get these results from these data.
Always tell what version of Oracle you are using. -
[8i] need help on query with a subquery/inline using UNION ALL view
OK, first of all let's start with some background info:
(1) I work in 8i
(2) some samples for my problem (please excuse the additional columns of data not used to this problem; I already had the sample laying around tables):
So, my first question was that I needed to find in the table RQMT who corresponded with everything on my VBOM have vbom.part_nbr table ' SAMPLE-1'. '. (Please note, in reality the VBOM table has thousands of rows of data, rather than just the 1 I have planned, some of them sharing the same vbom.part_nbr, others not). In addition to finding all RQMT data corresponding to the vbom.comp_part_nbr to vbom.part_nbr (where vbom.comp_part_nbr = rqmt.comp_part_nbr), I also need to find RQMT data for vbom.part_nbr itself (then, records where vbom.part_nbr = rqmt.comp_part_nbr).CREATE TABLE vbom ( part_nbr char(25) , bom_doc_nbr char(25) , bill_level number , comp_part_nbr char(25) , qty_per number ); --technically has primary and foreign keys, but whatever... --part_nbr is your top level (0) parent --comp_part_nbr is the specific child --bom_doc_nbr is the parent of the child (comp_part_nbr) and may be either part_nbr or a child of part_nbr that is also a parent INSERT INTO vbom VALUES ('SAMPLE-1','SAMPLE-1', 1,'SAMPLE-2',1); CREATE TABLE rqmt ( comp_part_nbr char(25) , prnt_part_nbr char(25) , ord_nbr char(10) , sub_ord_nbr char(3) , qty_reqd number , qty_issued number , date_reqd date , rqmt_stat char(2) , rqmt_type char(2) ); INSERT INTO rqmt VALUES ('SAMPLE-1','','S0000TEST1',001,30,0,TO_DATE('06/01/2010','mm/dd/yyyy'),'AL','ID'); INSERT INTO rqmt VALUES ('SAMPLE-2','SAMPLE-1','0000054963',001,15,10,TO_DATE('04/01/2010','mm/dd/yyyy'),'CL','DD'); INSERT INTO rqmt VALUES ('SAMPLE-2','SAMPLE-1','0000032562',001,5,5,TO_DATE('04/15/2010','mm/dd/yyyy'),'IS','DD'); INSERT INTO rqmt VALUES ('SAMPLE-2','SAMPLE-1','0000022341',001,5,4,TO_DATE('04/20/2010','mm/dd/yyyy'),'SH','DD'); INSERT INTO rqmt VALUES ('SAMPLE-2','SAMPLE-1','0000043469',001,10,0,TO_DATE('04/30/2010','mm/dd/yyyy'),'AL','DD'); INSERT INTO rqmt VALUES ('SAMPLE-2','SAMPLE-1','0000071235',001,10,0,TO_DATE('05/01/2010','mm/dd/yyyy'),'OP','DD'); INSERT INTO rqmt VALUES ('SAMPLE-2','SAMPLE-1','0000061224',001,5,0,TO_DATE('05/15/2010','mm/dd/yyyy'),'FP','DD'); INSERT INTO rqmt VALUES ('SAMPLE-2','SAMPLE-1','0000033294',001,5,0,TO_DATE('05/25/2010','mm/dd/yyyy'),'PL','DD');
To resolve this problem, I started with the following query:
It allows me to add a line to the top of the page parent (vbom.part_nbr), which does not exist in vbom.SELECT v.bill_level AS bill_lvl , v.comp_part_nbr AS component , v.bom_doc_nbr AS parent FROM VBOM v WHERE v.part_nbr ='SAMPLE-1' UNION ALL SELECT 0 AS bill_lvl , 'SAMPLE-1' AS component , NULL AS parent FROM DUAL
My first question is, is UNION ALL of the best way to do it, or could I do a kind of instruction based on the line number box (or something) that would be better? (in this application, or in the final query)
Then, I used the above query as a point of view online:
The problem here is that I have the same results (7 files) with the above query as I do with:SELECT a.bill_lvl , a.component , a.parent , r.ord_nbr , r.sub_ord_nbr , r.qty_reqd FROM ( SELECT v.bill_level AS bill_lvl , v.comp_part_nbr AS component , v.bom_doc_nbr AS parent FROM VBOM v WHERE v.part_nbr ='SAMPLE-1' UNION ALL SELECT 0 AS bill_lvl , 'SAMPLE-1' AS component , NULL AS parent FROM DUAL ) a , RQMT r WHERE a.component = r.comp_part_nbr
.. .it does not include RQMT recording for rqmt.comp_part_nbr = "SAMPLE-1'.SELECT v.bill_level , v.comp_part_nbr , v.bom_doc_nbr , r.ord_nbr , r.sub_ord_nbr , r.qty_reqd FROM VBOM v , RQMT r WHERE v.comp_part_nbr = r.comp_part_nbr AND v.part_nbr = 'SAMPLE-1'
To understand what was going on, I ran:
.. .and I get exactly this that I wait, 1 card for the SAMPLE-2 component and 1 plug for SAMPLE-1 (i.e. the recording I generated with the UNION ALL).SELECT a.bill_lvl , a.component , a.parent FROM ( SELECT v.bill_level AS bill_lvl , v.comp_part_nbr AS component , v.bom_doc_nbr AS parent FROM VBOM v WHERE v.part_nbr ='SAMPLE-1' UNION ALL SELECT 0 AS bill_lvl , 'SAMPLE-1' AS component , NULL AS parent FROM DUAL ) a
Then I ran:
.. .and I get all 8 records, whose SAMPLE-1.SELECT r.comp_part_nbr , r.ord_nbr , r.sub_ord_nbr , r.qty_reqd FROM RQMT r WHERE r.comp_part_nbr like 'SAMPLE-%'
So, it seems that the problem occurred when I join my opinion RQMT one online, although both separately seem to work very well.
A point to note: all parts of parent and child may not be appointed in the same way as in my example. SAMPLE-1 could have children of the SAMPLE-2, abc123, 20735, for example.
Any help on this would be appreciated, thanks!Hello
Concerns of problem by comparing 8 literal characters ' SAMPLE-1' for the 25-character CHAR column that contains "SAMPLE 1".»
17 spaces including the literal or use LPAD or CAST to 25 characters.
For example:SELECT a.bill_lvl , a.component , a.parent , r.ord_nbr , r.sub_ord_nbr , r.qty_reqd FROM ( SELECT v.bill_level AS bill_lvl , v.comp_part_nbr AS component , v.bom_doc_nbr AS parent FROM VBOM v WHERE v.part_nbr ='SAMPLE-1' UNION ALL SELECT 0 AS bill_lvl , CAST ('SAMPLE-1' AS CHAR (25)) -- CAST added here AS component , NULL AS parent FROM DUAL ) a , RQMT r WHERE a.component = r.comp_part_nbr ;
Is there a reason why you use CHAR instead of VARCHAR2? (One reason other than "I can't change it now.", otherwise said.)
-
INVALID IDENTIFIER error in the statement ON
I have problems with this SELECT statement in a report with the search items. The item sought in Question matches the string "Email". Any activity record that 'Email' in the field of the activity_type must be selected. The line of code is:
Select user_name, total of (select user_name, count (*) total from eba_ver2_cust_activity where activity_type = group e-mail user_name)
order by 2 desc, desc 2
There are some substitutions here. The 'Email' value is: P23_ACTIVITY_TYPE on the page.
The error I get is:
Failed to parse the SQL query:
ORA-00904: "EMAIL": invalid identifier
The problem is that the string constant is interpreted as an identifier name. Some sbustitutions are made to the general SELECT statement that fails. The relevant part of the code generating the wrong SELECTION is:
If: P23_ACTIVITY_TYPE! = 'null' and: P23_ACTIVITY_TYPE is not null then
If: P23_START_DATE is not null or: P23_END_DATE is not null then
l_sql: = l_sql | "and activity_type_id = ' |: P23_ACTIVITY_TYPE;"
on the other
l_sql: = l_sql | "where activity_type_id = ' |: P23_ACTIVITY_TYPE;
end if;
Anyway, the content of: P23_ACTIVITY_TYPE are treated as means of identification instead of a string. Help, please.
Steve "n00b" to Raleigh NCHi Steve,.
COBOL! If you've actually seen the real life before dinosaurs? ;) They still teach the last College I've heard...
What is the error you see? It can be as Tony said above, that you do not close your last statement. Here is what should look like this block of code:
if :P23_ACTIVITY_TYPE != '%null%' and :P23_ACTIVITY_TYPE is not null then if :P23_START_DATE is not null or :P23_END_DATE is not null then l_sql := l_sql || ' and activity_type_id = ''' || :P23_ACTIVITY_TYPE || ''''; else l_sql := l_sql || ' where activity_type_id = ''' || :P23_ACTIVITY_TYPE || ''''; end if; end if;
Note This is a series of simple "quotes.
Aaron
-
Hello OTN.
I don't understand why my sql query will pass by in the data model of the BI Publisher. I created a new data model, chose the data source and type of Standard SQL = SQL. I tried several databases and all the same error in BI Publisher, but the application works well in TOAD / SQL Developer. So, I think it might be something with my case so I'm tender hand to you to try and let me know if you get the same result as me.
The query is:
SELECT to_char (to_date ('15-' |)) TO_CHAR(:P_MONTH) | » -'|| (To_char(:P_YEAR), "YYYY-DD-MONTH") - 90, "YYYYMM") as yrmth FROM DUAL
Values of the variable:
: P_MONTH = APRIL
: P_YEAR = 2015
I tried multiple variations and not had much luck. Here are the other options I've tried:
WITH DATES AS
(
Select TO_NUMBER (decode (: P_MONTH, 'JANUARY', '01',))
'FEBRUARY', '02',.
'MARCH', '03'.
'APRIL', '04'
'MAY', '05'.
'JUNE', '06'.
'JULY', '07',.
'AUGUST', '08'.
'SEPTEMBER', '09'.
'OCTOBER', '10',.
'NOVEMBER', '11'.
"DECEMBER", "12."
'01')) as mth_nbr
of the double
)
SELECT to_char (to_date ('15-' |)) MTH_NBR | » -'|| (TO_CHAR(:P_YEAR), 'DD-MM-YYYY') - 90, "YYYYMM")
OF DATES
SELECT to_char (to_date ('15-' |: P_MONTH |)) » -'|| ((: P_YEAR, 'MONTH-DD-YYYY')-90, "YYYYMM") as yrmth FROM DUAL
I'm running out of ideas and I don't know why it does not work. If anyone has any suggestions or ideas, please let me know. I always mark answers correct and useful in my thread and I appreciate all your help.
Best regards
-Konrad
So I thought to it. It seems that there is a bug/lag between the guest screen that appears when you enter SQL in the data model and parameter values, to at model/value data.
Here's how I solved my problem.
I have created a new data model and first created all my settings required in the data model (including the default values without quotes, i.e. APRIL instead "Of APRIL") and then saved.
Then I stuck my sql query in the data model and when I clicked ok, I entered my string values in the message box with single quotes (i.e. "in APRIL' instead of APRIL)
After entering the values of string with single quotes in the dialog box, I was able to retrieve the columns in the data model and save.
In the data tab, is no longer, I had to enter the values in single quotes, but entered values normally instead, and the code worked.
It seems the box prompted to bind the values of the variables when the SQL text in a data model expects strings to be wrapped in single quotes, but no where else. It's a big headache for me, but I'm glad that I solved it, and I hope this can be of help to other institutions.
See you soon.
-
Hello
I have a table in my database, when I use
Select * from table_name; It gives me results
If I use
Select nom_de_colonne from table_name;
It gives me column-name is not a valid identifier.
I don't know I'm not the typos on column_name, any thoughts on what could be the problem
Thank youSomeone made the unfortunate decision to use quotes around column names when the table was created, and so the column name is in different cases. You must use now for always the quotes around the name of column
Select 'Sex' of the trial;
-
Apps BI - workflow task has received the error "invalid identifier".
Hi all
I'm loading acreage subject of projects using the client CAD for 11.5.10 container. And my Oracle EBS 11.5.10 only data source. Few of the workflow tasks failed. For example: "SDE_ORA_TaksDimension." When I checked the logs of session, its display like "ORA-00904 'PA_PROJ_ELEMENT_VERSIONS'." FINANCIAL_TASK_FLAG ': invalid identifier "error of a few paintings of projects (PA). I checked in the database to Oracle 11.5.10 and noticed that the column (FINANCIAL_TASK_FLAG) itself is not there in the table (PA_PROJ_ELEMENT_VERSIONS).
I also checked SDE_ORA_TaksDimension in "SDE_ORA11510_Adaptor" mapping in the table PA_PROJ_ELEMENT_VERSIONS Design, Informatica PowerCenter Workflow is to have the column with "FINANCIAL_TASK_FLAG".
In other words, there are some differences between available "SDE_ORA11510_Adaptor" and Oracle EBS 11.5.10 database. Could someone please help me or guide me to solve this problem?
Thank you
Harish NunnThis is probably because you do not have the PRE REQUISIUTE following for PROJECT ANALYTICS for 11.5.10:
requires the Family Pack M (11i. PJ_PF. (M) to be applied to Oracle eBusiness Suite 11.5.10.
You need to run the analytical project.
Check the answer as CORRECT
-
Get the error invalid identifier in the left outer join
I wrote a query and get the invalid identifier error during execution:
the exact error is: ORA-00904: "D". "" ACCT_NO ": invalid identifier
This query is not able to access the parent table alias in the subquery of the left outer join.
This is the query:
SELECT D.PROD_DESC_TX, BASE. ASSET_NUM, BASE. PROD_ID, BASE.NAME
OF TABLE1 D
LEFT OUTER JOIN
(
SELECT ASSET_NUM, PROD_ID, B.SID
FROM TABLE2 E
JOIN IN-HOUSE TABLE3 HAS IT E.PROD_ID = A.ROW_ID
JOIN INTERNAL TABLE 4 C ON A.PAR_PROD_INT_ID = C.ROW_ID
INTERNAL TABLE5 JOIN B ON C.ROW_ID = B.PAR_ROW_ID
AND B.TYPE = 'VALUE '.
AND B.NAME = 'VALUE '.
WHERE E.ASSET_NUM = ((CASE WHEN LTRIM (RTRIM (D.BANK_NO)) = '021 ' THEN '021' ELSE ' 020' END) |) LTRIM (RTRIM (D.APPL_CD)). LTRIM (RTRIM (D.ACCT_NO)))
) BASE ON ((CASE WHEN LTRIM (RTRIM (D.BANK_NO)) = '021 ' THEN '021' ELSE ' 020' END) |) LTRIM (RTRIM (D.APPL_CD)). LTRIM (RTRIM (D.ACCT_NO))) = BASE. ASSET_NUM
WHERE D.BANK_NO = 'VALUE '.
AND D.APPL_CD = 'VALUE '.
AND D.ACCT_NO = 'VALUE '.
Edited by: user648525 13 Sep, 2011 01:21I can easily look at your request at this time (using my iPhone on a train).
But trying out this line in the WHERE (the one with the invalid reference) clause in the main query.
Who is... in the view of inline, use only the logic of the join (the clauses).
Overflow the filtering logic (WHERE clause) to the main request. You may need to select some additional inline view columns to make these references work.
-
During execution of the query below, I get ORA-00904 as invalid identifier error.
But when I execute view inline that it gives the result.
I'm giving all types of data correctly.
Select EMP_QUERY. "' Empno ' EMPNO,. EMP_QUERY. "' Ename ' ENAME, EMP_QUERY. """" "Job", EMP_QUERY. "" Bishop "MGR. EMP_QUERY. "" HireDate "HIREDATE. EMP_QUERY. "' SAL ' SAL, EMP_QUERY. "Comm"COMM, EMP_QUERY. "DEPTNO"DEPTNO ". Of ( Select empno, ename, job, mgr, Hiredate, sal, comm, deptno SRC_1.EMP_SRC_11
) EMP_QUERY
where (1 = 1) That's because you specified the column name in the selection external double quotes.
EMP_QUERY. "' Empno ' EMPNO
Why does. To take
emp_query.EmpNo as 'Empno '.
-
ORA-00904: "I." "" PROCESS_FLAG ": invalid identifier - I is a var slider
create or replace PROCEDURE validate_data_proc
IS
CURSOR c1
IS
SELECT itemname, ICT, msib mtl_system_items_b item_conv_tab_sv itemname1 msib.segment1 icts.item_name
where icts.item_name! = msib.segment1;
CURSOR c2
IS
SELECT TIC. Nom_element itemname, icts.ORGANIZATION_ID org, msib.segment1 itemname1, msib.organization_id the item_conv_tab_sv ICT, msib mtl_system_items_b org1
where icts.organization_id = msib.organization_id and icts.item_name! = msib.segment1;
BEGIN
I'm IN c1
LOOP
-Select i.item_name from i in
If (c1% notfound) then
FOR r IN c2
LOOP
If (c2% notfound) then
update of HCCI process_flag = 3 set item_conv_tab_sv where item_conv_tab_sv.item_name = r.item_name;
on the other
update of item_conv_tab_sv HCCI set process_flag = 1 where item_conv_tab_sv.item_name = r.item_name;
end if;
end loop;
on the other
update of HCCI process_flag = 3 set item_conv_tab_sv where item_conv_tab_sv.item_name = i.item_name;
end if;
COMMIT;
end loop;
END validate_data_proc;
I use a cursor nested which I create that err
I get the foll error message,
Error (23.30): PL/SQL: statement ignored
Error (23,116): PL/SQL: ORA-00904: 'R '. "" Nom_element ": invalid identifier
Error (23,118): PLS-00302: component 'Nom_élément' must be declared
Error (26,32): PL/SQL: statement ignored
Error (26,109): PL/SQL: ORA-00904: 'R '. "" PROCESS_FLAG ": invalid identifier
Error (26,111): PLS-00302: component 'PROCESS_FLAG' must be declared
Error (30,31): PL/SQL: statement ignored
Error (30,108): PL/SQL: ORA-00904: "I." "" PROCESS_FLAG ": invalid identifier
Error (30,110): PLS-00302: component 'PROCESS_FLAG' must be declared
Error (26,118): PL/SQL: ORA-00904: 'R '. "" Nom_element ": invalid identifier
Error (26,120): PLS-00302: component 'Nom_élément' must be declared
Error (30,117): PL/SQL: ORA-00904: "I." "" Nom_element ": invalid identifier
Error (30,119): PLS-00302: component 'Nom_élément' must be declared
someone... Help, please...Find a difference:
CURSOR c1
IS
SELECT icts.item_name itemname , msib.segment1 itemname1 of the item_conv_tab_sv ICT, mtl_system_items_b msib
where icts.item_name! = msib.segment1;
CURSOR c2
IS
SELECT TIC. Nom_element itemname, icts.ORGANIZATION_ID org, msib.segment1 itemname1, msib.organization_id item_conv_tab_sv cts, mtl_system_items_b msib org1
where icts.organization_id = msib.organization_id and icts.item_name! = msib.segment1;And:
update of HCCI process_flag = 3 set item_conv_tab_sv where item_conv_tab_sv.item_name = rnom_element;
Update item_conv_tab_sv set process_flag icss = 3 where item_conv_tab_sv.item_name = i.nom_element;But even in this case, your code is wrong for CURSOR loop retrieves a line and stops automatically when there is no lines. Therefore, there is no sense to check notfound % c1 inside the loop for the SLIDER - this will be always FALSE. If your interior for CURSOR LOOP (C2) will never run.
SY.
-
can we use to_date using Union or Union
Hi, while I do any union with two tables I get
ORA-01790: expression must have same type of data, matching expression
01790 00000 - "expression must have the same type of data, matching expression.
and if I change this data type of TO_CHAR is showing correct result
SELECT (TO_CHAR (C61_CURRENT_MONTH, ' MON-DD-YYYY "") CURRENT_MONTH EDW.) C$ _0VW_TEMP_PLAYER_DTL_LOAD
UNION ALL
SELECT (TO_CHAR (C17_CURRENT_MONTH, ' MON-DD-YYYY "") CURRENT_MONTH EDW.) C$ _1VW_TEMP_PLAYER_DTL_LOAD
and I'm going to insert this result in a table which column is defined as the DATE data type
so I tried below one as
Select to_date (TO_CHAR (C61_CURRENT_MONTH, ' MON-DD-YYYY ""), 'dd-mon-yyyy') CURRENT_MONTH OF EDW. C$ _0VW_TEMP_PLAYER_DTL_LOAD
UNION ALL
TO_DATE (TO_CHAR (C17_CURRENT_MONTH, ' MON-DD-YYYY ""), 'dd-mon-yyyy') CURRENT_MONTH OF EDW. C$ _1VW_TEMP_PLAYER_DTL_LOAD
but I get the error message like
ORA-01790: expression must have same type of data, matching expression
so my question is can we use to_date using union all.Maybe do you the conversion to remove time from date values.
This could be done better with:
select trunc(C61_CURRENT_MONTH) CURRENT_MONTH FROM EDW.C$_0VW_TEMP_PLAYER_DTL_LOAD UNION ALL select trunc(C17_CURRENT_MONTH) CURRENT_MONTH FROM EDW.C$_1VW_TEMP_PLAYER_DTL_LOAD
I can't reproduce your original error, because I do not have your tables (test data would be nice)
and no doubt I'm on another database-version (we do not know your version of db).Published by: hm on 19.04.2012 04:30
-
ORA-00904: "A". "" LVCI_ISSUEDATE ": invalid identifier
Hello
I get (ORA-00904: "A".) ("' LVCI_ISSUEDATE ': invalid identifier) error for the following query...
SELECT A.lvci_issuedate, A.lvci_lotno, (SELECT B.cot_desc FROM tb_lvm_cottondesc B
WHERE B.cot_seqno_pk = A.lvci_cottonno) AS cotton.
A.lvci_nbales, (SELECT C.lvcr_rate FROM tb_lvm_cottonreceipt C WHERE C.lvcr_cottonno = A.lvci_cottonno
AND C.lvcr_invdate = (SELECT MAX (lvcr_invdate) FROM (SELECT D.lvcr_invdate FROM tb_lvm_cottonreceipt D.lvcr_invdate D WHERE < A.lvci_issuedate))) AS RATE, A.lvci_weight, A.lvci_issuedate tb_lvm_cottonissue A.lvci_issuedate A WHERE BETWEEN to_date (January 12, 2008 ', ' dd/mm/yyyy') AND to_date (June 12, 2008 ', ' dd/mm/yyyy')
I use Oracle 9i.
Could you give me solution to this problem? What's not in my sql query?Hi psram.
First bad thing, it's that you format your query in order to make it readable.
SELECT A.lvci_issuedate , A.lvci_lotno , (SELECT B.cot_desc FROM tb_lvm_cottondesc B WHERE B.cot_seqno_pk = A.lvci_cottonno) AS cotton , A.lvci_nbales , (SELECT C.lvcr_rate FROM tb_lvm_cottonreceipt C WHERE C.lvcr_cottonno = A.lvci_cottonno AND C.lvcr_invdate = (SELECT MAX(lvcr_invdate) FROM (SELECT D.lvcr_invdate FROM tb_lvm_cottonreceipt D WHERE D.lvcr_invdate < *A.lvci_issuedate*))) AS RATE , A.lvci_weight , A.lvci_issuedate FROM tb_lvm_cottonissue A WHERE A.lvci_issuedate BETWEEN to_date('01/12/2008', 'dd/mm/yyyy') AND to_date('06/12/2008', 'dd/mm/yyyy');
Then it is nested too deep, I think it's the same thing:
SELECT A.lvci_issuedate , A.lvci_lotno , (SELECT B.cot_desc FROM tb_lvm_cottondesc B WHERE B.cot_seqno_pk = A.lvci_cottonno) AS cotton , A.lvci_nbales , (SELECT C.lvcr_rate FROM tb_lvm_cottonreceipt C WHERE C.lvcr_cottonno = A.lvci_cottonno AND C.lvcr_invdate = (SELECT MAX(lvcr_invdate) FROM tb_lvm_cottonreceipt D WHERE D.lvcr_invdate < A.lvci_issuedate)) AS RATE , A.lvci_weight , A.lvci_issuedate FROM tb_lvm_cottonissue A WHERE A.lvci_issuedate BETWEEN to_date('01/12/2008', 'dd/mm/yyyy') AND to_date('06/12/2008', 'dd/mm/yyyy');
Try, but I thing it is always nested deep
Concerning
Peter -
Union all with addistional field
Hello
Maybe this is a stupid question.
I have two tables with 22 columns.
Another table with 23 columns
I want to combine these two tables using union all.
In the first picture, I want back "NA" as the last field.
In the second table, last column is varchar2.
Instead of every column one by one and if I use select * in two queries and add "NA" to one?
I want the union two queries can order and use it with the clause to retrieve values based on conditions somany.
So I have to specify the names of column three times.
I use oracle 10g
Hello Krishna,
Try
select t1.*, 'NA' as
from table1 t1 union select t2.* from table2 t2; concerning
Kay
-
Please help me with the Alternative of queries to replace the UNION ALL for two queries
Hi all
I have the query to retrieve assets employees salary count and in so far as below:
Select ename, emp_no, sum (sal_till_2010), sum (sal_till_2014) of
(select emp_no, ename, salary as sal_till_2010, 0 as sal_till_2014 of employee e1
where effective_date < = 1 January 2010 ' and not exists (select 1 from e2 employee_deletion where e2.emp_no = e1.emp_no and e2.deletion_date < = January 1, 2010 "")
UNION ALL
Select ename, emp_no, 0 as sal_till_2010, salary as employee e1 sal_till_2014 - here is a dummy 0 salary until 2010 for the union of all the
where effective_date < = 1 January 2014 "and not exists (select 1 from e2 employee_deletion where e2.emp_no = e1.emp_no and e2.deletion_date < = 1 January 2014") "
Group of emp_no, ename;
In this query, I get the total salary until 2010 and until 2014 in the employee table, dates are dynamically passed to the procedure, and this can change.
But assume the date above and let me know the alternative of queries to improve performance because I use Union ALL and read the same table twice in the above query.
Advice me with request to read the table once to fetch the same data as the above query.
Thanks in advance.
Hello
Thanks for the display of the data of the sample; It's very useful!
I think OP wants something like this:
WITH cutoff_dates AS
(
SELECT TO_DATE (January 1, 2010 ', ' DD/MM/YYYY') AS cutoff_date, 2010 UNDER the label OF dual UNION ALL
SELECT TO_DATE (1 January 2014 ', "DD/MM/YYYY"), double 2014
)
SELECT e.emp_no, e.ename
, NVL (SUM (CASE WHEN c.label = 2010 THEN e.salary END), 0) AS sal_till_2010
, NVL (SUM (CASE WHEN c.label = 2014 THEN e.salary END), 0) AS sal_till_2014
E employee
JOIN cutoff_dates c ON e.effective_date<=>=>
WHERE DOES NOT EXIST)
SELECT 1
Of employee_deletion ed
WHERE ed.emp_no = e.emp_no
AND ed.deletion_date<=>=>
)
E.emp_no GROUP, e.ename
ORDER BY e.emp_no
;
Output of your sample data:
EMP_NO ENAME SAL_TILL_2010 SAL_TILL_2014
---------- ------ ------------- -------------
1 Mickey 450 0
2 Donald 750 0
-
What better union all or create a separate slider
Hi gurus
I wonder if someone can help out me of this union is a good option, or create a separate slider for each union all is a good option. Which is preferable? Thanks in advance
Concerning
Shu
You can use Union all instead of opening cursor much time to record the line and your code in the treatment of the sliders, exceptions.
So it would be better to consider all the data at once and even within a single processing loop.
Kind regards
Prashant da Silva
Maybe you are looking for
-
Internet security alert - popup
When I go on Google, I get a pop up saying Internet Security Alert.
-
I have an iPhone running iOS 9.2.1 6s my wifi suddenly disconnects, and after a few seconds that it reconnects, it happens most of the time help me thank you!
-
data table how to separate?
Hey everybody, How can I separate the table of data, which is in a graphic visualization and analysis columns txt file? Marek
-
I get disable key 93979652 systems after failing to remember my password! Any help guys?
-
Can I change the size of icons?
Hi, I'm updating my phone last night and sizes of icons are charged (largest) and now I can't find the setting to change sizes of iconsIssue of MT is I can change it and if I were is the setting? And I'm sorry that my English grammar is not so goodTh