Oracle Join
TableA
hierarchy_id Child_level parent_level
1 4 null
1 3 4
1 2 3
TableB
Enitity_id level
1 4
1 3
1 2
1 1
Tablec
level level_type
1 1
2 2
3 2
4 3
Tabled
Entity_id Hierarchy_id
1 1
2 2
From the above tables i have to build a query that returns
Entity_id Hierarchy_id Child_level parent_level
1 1 4 null
1 1 3 4
1 1 2 3
1 null 1 null
How can i achieve this, the main problem i am facing is getting the child level '1' of type '1' in the result set,
as it is not linked to a hierarchy id.
Please suggest.
Hi,
Not knowing exactly what you mean, prerequisites are quite vague, but i should use a union.
What about this?
select d.entity_id, a.hierarchy_id, a.child_level, a.parent_level
from tabled d, tablea a
where d.HIERARCHY_ID = a.HIERARCHY_ID
union
select d.entity_id, NULL, b.e_level, NULL
from tabled d, tableb b
where d.entity_id = b.ENTITY_ID
and not exists (select 'dummy'
from tablea a
where a.CHILD_LEVEL = b.E_LEVEL)
order by 1, 2 , 3 desc
ENTITY_ID HIERARCHY_ID CHILD_LEVEL PARENT_LEVEL
1 1 4
1 1 3 4
1 1 2 3
1 1
SQL> Kind regards
Auke Quist
Similar Messages
-
Difference between oracle join syntaxes and ANSI join syntaxes
What is difference between oracle join syntaxes and ANSI join syntaxes ?
why oracle is having different syntaxes for joins than ANSI syntaxes ?
Also Join syntaxes are different in some oracle vesrions ?BluShadow wrote:
3360 wrote:
Yes it is. The Oracle database wasn't initially designed to be ANSI compliant. As you correctly state the ANSI standards weren't around when it was initially designed, so the statement is perfectly correct. ;)Ok, in one sense it may be correct but it is a completely misleading statement. Not sure why you think it's misleading.Because there was no ANSI standard, so making it sound like a design choice The Oracle database wasn't initially designed to be ANSI compliant. would suggest to most readers that there was a standard to be compliant to.
Like saying Ford originally did not design their cars to incorporate safety features such as ABS, seat belts and air bags.
The OP asked "why oracle is having different syntaxes for joins than ANSI syntaxes ?" and the answer is that Oracle wasn't initially designed with ANSI compliance, so it has it's old non-ANSI syntax,As shown above, the old syntax was ANSI compliant at the time and to call it non-ANSI is either incorrect or misleading dependent on your point of view.
and since ANSI syntax became the standard it now supports that. And since ANSI switched to a new standard, Oracle had to implement the new standard as well as the previous ANSI standard would be more accurate in my opinion.
Nothing misleading as far as I'm aware in that.I find the whole discussion about ANSI and Oracle's supposed non-compliance, reads like it was Oracle's choice to deviate from the standards, when it was ANSI's bullheaded decisions to pointlessly change standards that left Oracle and other vendors out of compliance, and that was a decision made solely by ANSI.
This is probably the reason ANSI no longer produces SQL standards, the endless syntax fiddling would eventually have made forward left under outer joins a reality.
{message:id=1785128} -
Sequence of execution of Oracle Joins
Hi All,
I am applying combination of outer-join & equi-join on around 5-6 tables.
But I am not getting expected results.
I just wanted to know how Oracle applies execution of this joins, outer & equi.Here is the data on which I am playing,
--Employee table
CREATE TABLE "EMP"
("EMP_ID" NUMBER(10,0) NOT NULL ENABLE,
"FNAME" NVARCHAR2(50) NOT NULL ENABLE,
"LNAME" NVARCHAR2(50) NOT NULL ENABLE
--Mapping between Task type & Department
CREATE TABLE "TASKTYPE_FOR_DEPT"
( "TASKTYPE_FOR_DEPT_ID" NUMBER(10,0) NOT NULL ENABLE,
"DEPT_ID" NUMBER(10,0) NOT NULL ENABLE,
"TASK_TYPE_CD" NVARCHAR2(10) NOT NULL ENABLE
-- Departmentwise employee hierarchy
CREATE TABLE "EMP_HIERARCHY"
( "EMP_ID" NUMBER(10,0) NOT NULL ENABLE,
"DEPT_ID" NUMBER(10,0) NOT NULL ENABLE
-- Tasks Details
CREATE TABLE "TASKS"
( "TASK_ID" NUMBER(10,0) NOT NULL ENABLE,
"TASK_PRIORITY" NVARCHAR2(10) NOT NULL ENABLE,
"TASK_TYPE" VARCHAR2(20 BYTE)
-- Tasks allocation
CREATE TABLE "TASKSALLOCATION"
( "TASKALLOCATION_ID" NUMBER(10,0) NOT NULL ENABLE,
"EMP_ID" NUMBER(10,0) NOT NULL ENABLE,
"TASK_ID" NUMBER(10,0) NOT NULL ENABLE
Insert into EMP (EMP_ID,FNAME,LNAME) values (1,'XYZ','DFD');
Insert into EMP (EMP_ID,FNAME,LNAME) values (2,'DFDS','FD');
Insert into EMP (EMP_ID,FNAME,LNAME) values (3,'FDSF','GFH');
Insert into EMP (EMP_ID,FNAME,LNAME) values (6,'GFHGF','GFHS');
Insert into EMP (EMP_ID,FNAME,LNAME) values (4,'GFD','FDG');
Insert into EMP (EMP_ID,FNAME,LNAME) values (5,'DSFDS','FDSAF');
Insert into EMP (EMP_ID,FNAME,LNAME) values (7,'GHGY','EWE');
Insert into EMP (EMP_ID,FNAME,LNAME) values (8,'FGRFSAD','SADF');
Insert into TASKTYPE_FOR_DEPT (TASKTYPE_FOR_DEPT_ID,DEPT_ID,TASK_TYPE_CD) values (1,1,'T1');
Insert into EMP_HIERARCHY (EMP_ID,DEPT_ID) values (1,1);
Insert into EMP_HIERARCHY (EMP_ID,DEPT_ID) values (2,1);
Insert into EMP_HIERARCHY (EMP_ID,DEPT_ID) values (3,1);
Insert into EMP_HIERARCHY (EMP_ID,DEPT_ID) values (4,1);
Insert into EMP_HIERARCHY (EMP_ID,DEPT_ID) values (5,1);
Insert into EMP_HIERARCHY (EMP_ID,DEPT_ID) values (6,1);
Insert into EMP_HIERARCHY (EMP_ID,DEPT_ID) values (7,1);
Insert into EMP_HIERARCHY (EMP_ID,DEPT_ID) values (8,1);
Insert into TASKS (TASK_ID,TASK_PRIORITY,TASK_TYPE) values (1,'HIGH','T1');
Insert into TASKS (TASK_ID,TASK_PRIORITY,TASK_TYPE) values (2,'MEDIUM','T1');
Insert into TASKS (TASK_ID,TASK_PRIORITY,TASK_TYPE) values (3,'LOW','T1');
Insert into TASKS (TASK_ID,TASK_PRIORITY,TASK_TYPE) values (4,'HIGH','T1');
Insert into TASKS (TASK_ID,TASK_PRIORITY,TASK_TYPE) values (5,'MEDIUM','T1');
Insert into TASKS (TASK_ID,TASK_PRIORITY,TASK_TYPE) values (6,'LOW','T1');
Insert into TASKS (TASK_ID,TASK_PRIORITY,TASK_TYPE) values (7,'HIGH','T1');
Insert into TASKS (TASK_ID,TASK_PRIORITY,TASK_TYPE) values (8,'MEDIUM','T1');
Insert into TASKS (TASK_ID,TASK_PRIORITY,TASK_TYPE) values (9,'LOW','T1');
Insert into TASKS (TASK_ID,TASK_PRIORITY,TASK_TYPE) values (10,'HIGH','T1');
Insert into TASKS (TASK_ID,TASK_PRIORITY,TASK_TYPE) values (11,'MEDIUM','T1');
Insert into TASKS (TASK_ID,TASK_PRIORITY,TASK_TYPE) values (12,'LOW','T1');
Insert into TASKS (TASK_ID,TASK_PRIORITY,TASK_TYPE) values (13,'HIGH','T1');
Insert into TASKS (TASK_ID,TASK_PRIORITY,TASK_TYPE) values (14,'MEDIUM','T1');
Insert into TASKS (TASK_ID,TASK_PRIORITY,TASK_TYPE) values (15,'LOW','T1');
Insert into TASKS (TASK_ID,TASK_PRIORITY,TASK_TYPE) values (16,'HIGH','T1');
Insert into TASKS (TASK_ID,TASK_PRIORITY,TASK_TYPE) values (17,'MEDIUM','T1');
Insert into TASKS (TASK_ID,TASK_PRIORITY,TASK_TYPE) values (18,'LOW','T1');
Insert into TASKS (TASK_ID,TASK_PRIORITY,TASK_TYPE) values (19,'HIGH','T1');
Insert into TASKS (TASK_ID,TASK_PRIORITY,TASK_TYPE) values (20,'MEDIUM','T1');
Insert into TASKS (TASK_ID,TASK_PRIORITY,TASK_TYPE) values (21,'LOW','T1');
Insert into TASKS (TASK_ID,TASK_PRIORITY,TASK_TYPE) values (22,'HIGH','T1');
Insert into TASKS (TASK_ID,TASK_PRIORITY,TASK_TYPE) values (23,'MEDIUM','T1');
Insert into TASKS (TASK_ID,TASK_PRIORITY,TASK_TYPE) values (24,'LOW','T1');
Insert into TASKSALLOCATION (TASKALLOCATION_ID,EMP_ID,TASK_ID) values (1,1,1);
Insert into TASKSALLOCATION (TASKALLOCATION_ID,EMP_ID,TASK_ID) values (2,2,1);
Insert into TASKSALLOCATION (TASKALLOCATION_ID,EMP_ID,TASK_ID) values (3,3,2);
Insert into TASKSALLOCATION (TASKALLOCATION_ID,EMP_ID,TASK_ID) values (4,3,3);
Insert into TASKSALLOCATION (TASKALLOCATION_ID,EMP_ID,TASK_ID) values (5,4,4);
Insert into TASKSALLOCATION (TASKALLOCATION_ID,EMP_ID,TASK_ID) values (6,4,5);
Insert into TASKSALLOCATION (TASKALLOCATION_ID,EMP_ID,TASK_ID) values (7,4,6);
Insert into TASKSALLOCATION (TASKALLOCATION_ID,EMP_ID,TASK_ID) values (8,4,7);
Insert into TASKSALLOCATION (TASKALLOCATION_ID,EMP_ID,TASK_ID) values (9,5,6);
Insert into TASKSALLOCATION (TASKALLOCATION_ID,EMP_ID,TASK_ID) values (10,6,8);
Insert into TASKSALLOCATION (TASKALLOCATION_ID,EMP_ID,TASK_ID) values (12,8,8);
Insert into TASKSALLOCATION (TASKALLOCATION_ID,EMP_ID,TASK_ID) values (13,8,10);
Insert into TASKSALLOCATION (TASKALLOCATION_ID,EMP_ID,TASK_ID) values (14,8,11);
Insert into TASKSALLOCATION (TASKALLOCATION_ID,EMP_ID,TASK_ID) values (15,8,12);
Insert into TASKSALLOCATION (TASKALLOCATION_ID,EMP_ID,TASK_ID) values (16,6,13);
Insert into TASKSALLOCATION (TASKALLOCATION_ID,EMP_ID,TASK_ID) values (17,5,14);
Insert into TASKSALLOCATION (TASKALLOCATION_ID,EMP_ID,TASK_ID) values (18,3,12);
Insert into TASKSALLOCATION (TASKALLOCATION_ID,EMP_ID,TASK_ID) values (19,3,13);
Insert into TASKSALLOCATION (TASKALLOCATION_ID,EMP_ID,TASK_ID) values (20,2,15);
Insert into TASKSALLOCATION (TASKALLOCATION_ID,EMP_ID,TASK_ID) values (21,1,16);
Insert into TASKSALLOCATION (TASKALLOCATION_ID,EMP_ID,TASK_ID) values (22,2,17);
Insert into TASKSALLOCATION (TASKALLOCATION_ID,EMP_ID,TASK_ID) values (23,1,18);
Insert into TASKSALLOCATION (TASKALLOCATION_ID,EMP_ID,TASK_ID) values (24,4,19);
Insert into TASKSALLOCATION (TASKALLOCATION_ID,EMP_ID,TASK_ID) values (25,6,20);
Insert into TASKSALLOCATION (TASKALLOCATION_ID,EMP_ID,TASK_ID) values (26,5,21);
Insert into TASKSALLOCATION (TASKALLOCATION_ID,EMP_ID,TASK_ID) values (27,1,22);
Insert into TASKSALLOCATION (TASKALLOCATION_ID,EMP_ID,TASK_ID) values (28,3,23);
COMMIT;We want all resources belongs to department for a given case type with assinged tasks count & grouping with priority.
I tried the following query,
select emp.fname || ' ' || emp.lname EMP_NAME
, sum(DECODE(tasks.TASK_PRIORITY, 'HIGH', 1, 0)) HIGH
, sum(DECODE(tasks.TASK_PRIORITY, 'MEDIUM', 1, 0)) MEDIUM
, sum(DECODE(tasks.TASK_PRIORITY, 'LOW', 1, 0)) LOW
from emp,
EMP_HIERARCHY,
TASKSALLOCATION,
TASKS,
TASKTYPE_FOR_DEPT
where
TASKTYPE_FOR_DEPT.TASK_TYPE_CD = 'T1'
emp.EMP_ID = TASKSALLOCATION.EMP_ID(+)
and TASKSALLOCATION.TASK_ID = tasks.TASK_ID(+)
and tasks.TASK_TYPE = TASKTYPE_FOR_DEPT.TASK_TYPE_CD
and TASKTYPE_FOR_DEPT.dept_id = EMP_HIERARCHY.dept_id
-- and EMP_HIERARCHY.emp_id = emp.EMP_ID
group by emp.fname || ' ' || emp.lname;
It is not working properly.
Actually we are also looking the employee for whom task has been not allocated but belong to same department.
In above resultset employee 'GHGY EWE'.
We are expecting resultset something like this.
with
t as
select 'GFHGF GFHS' as emp_name, 1 as highPriority, 2 as mediumPriority, 0 as lowPriority FROM dual union all
select 'FDSF GFH', 1 , 2 , 2 FROM dual union all
select 'XYZ DFD' , 3 , 0 , 1 FROM dual union all
select 'GHGY EWE', 0 , 0 , 0 FROM dual union all
select 'DFDS FD', 1 , 1 , 1 FROM dual union all
select 'GFD FDG', 3 , 1 , 1 FROM dual union all
select 'FGRFSAD SADF', 1 , 2 , 1 FROM dual union all
select 'DSFDS FDSAF', 0 , 1 , 2 FROM dual
);Note : We are using Oracle 11.2.0.2.0 version -
Converting oracle join to Ansi sql join
Hi Guys,
I am new to SQL and trying to convert the following Oracle query (joins) into ANSI sql joins...Can someone please help me?
SELECT M.EXTERNALCODE, M.NAME AS MNAME, SC.BIRIM, SM.TRANSACTIONDATE, SMD.AMOUNT,
SMD.UNITPRICE, SM.ID AS SMID, SMD.ID AS SMDID, F.NAME AS FNAME,
IFNULL (SMD.AMOUNT, 0, SMD.AMOUNT) * IFNULL (SMD.UNITPRICE, 0, SMD.UNITPRICE) AS TOTALPRICE, SMD.AMOUNT AS RECEIVED_QUANTITY,
PD.ORDERID, PD.AMOUNT QUANTITY, PO.PROCESSDATE
FROM STOCKMAINTRANSACTION SM,
STOCKMAINTRANSACTIONDETAIL SMD,
MATERIAL M,
STOCKCARD SC,
FVSTOCK FVS,
FIRM F,
PURCHASEORDER PO,
PURCHASEORDERDETAIL PD,
PURCHASEORDERDETAILSUPPLIED PDS
WHERE SM.ID = SMD.MAINTRANSACTIONID
AND SMD.MATERIALID = M.ID
AND SMD.STOCKCARDID = SC.ID
AND SM.PROPREF = FVS.RECORDID(+)
AND FVS.FIELDID(+) = 2559
AND FVS.FLEVEL(+) = 'F'
AND F.ID(+) = SUBSTR (FVS.FVALUE, 1, 9)
AND SM.TRANSDEFID in (999,2329,2344,2370,150000903,150005362)
AND SMD.CANCELLED = 0
AND SMD.STOCKUPDATED = 1
AND SMD.ID = PDS.STOCKMAINTRANSACTIONDETAILID
AND PDS.ORDERDETAILID = PD.ORDERDETAILID
AND PO.ORDERID = PD.ORDERID
AND (M.ID = {@MATERIALID@} OR {@MATERIALID@} = 0)
AND (SM.STOREID = {@STOREID@} OR {@STOREID@} = 0)
AND (F.ID = {@SUPPLIERID@} OR {@SUPPLIERID@} = 0)
AND SM.TRANSACTIONDATE BETWEEN {@STARTDATE@} AND {@ENDDATE@}
ORDER BY F.NAME, M.EXTERNALCODE, SM.TRANSACTIONDATE
Really appreciate the help!
Thanks.Hi,
Welcome to the forum!
To convert to ANSI syntax, replace join conditions in the WHERE clause
FROM x
, y
WHERE x.x1 = y.y1
AND x.x2 = y.y2with ON conditions in the FROM clause:
FROM x
JOIN y ON x.x1 = y.y1
AND x.x2 = y.y2In inner joins, conditions that do not reference 2 tables are not really join conditions, so it doesn't matter if they are in the FROM clause or in the WHERE clause.
In your case
SM.TRANSDEFID in (999,2329,2344,2370,150000903,150005362)could be part of a join condition involving sm, or it could be in the WHERE clause. Most people find it clearer if 1-table conditions like this are in the WHERE clause.
Again, this only applies to inner joins. For outer joins, all conditions that apply to a table that may lack matching rows must be included in the FROM clause, like this:
LEFT OUTER JOIN fvstock fvs ON sm.propref = fvs.recordid
AND fvs.fieldid = 2559
AND fvs.flevel = 'F'Try it.
If you have trouble, post your best attempt, along with CREATE TABLE and INSERT statements for a little sample data from all the tables involved, and the results you want from that data. Simplify the problem. Post only the tables and columns that you don't know how to handle.
See the forum FAQ {message:id=9360002}
user8428528 wrote:
AND (M.ID = {@MATERIALID@} OR {@MATERIALID@} = 0)
AND (SM.STOREID = {@STOREID@} OR {@STOREID@} = 0)
AND (F.ID = {@SUPPLIERID@} OR {@SUPPLIERID@} = 0)
AND SM.TRANSACTIONDATE BETWEEN {@STARTDATE@} AND {@ENDDATE@}This is not valid Oracle SQL. Is {@MATERIALID@} some kind of variable? -
Hi,
Can somebody please help me join the 2 queries I am posting below. I am having a hard time with them. There are some common tables in both of them.
Query 1 :
select "LAST_NAME"||', '||"FIRST_NAME" from
TV_LABCASE c join TV_LABASSIGN a on c."CASE_KEY"=a."CASE_KEY"
JOIN TV_REPTNAME n on a."EXAM_KEY"= n."EXAM_KEY"
join TV_LABNAME LN ON n."NAME_KEY"=ln."NAME_KEY"
WHERE "LAB_CASE"='10-000747';
Query2:
select "ITEM_TYPE" from
TV_LABCASE c join TV_LABASSIGN a on c."CASE_KEY"=a."CASE_KEY"
join TV_ITASSIGN n on a."EXAM_KEY" = n."EXAM_KEY"
join TV_LABITEM ln on n."EVIDENCE_CONTROL_NUMBER" = ln."EVIDENCE_CONTROL_NUMBER"
WHERE "LAB_CASE"='10-000747';
Please help me take the common ones out and make it a combined query. Both singel queries work without any error.
Thanks in advance!!!Thanks a lot, it works, just a small mistake with the variables.
select "LAST_NAME"||', '||"FIRST_NAME", "ITEM_TYPE" from
TV_LABCASE c join TV_LABASSIGN a on c."CASE_KEY"=a."CASE_KEY"
JOIN TV_REPTNAME p on a."EXAM_KEY"= p."EXAM_KEY"
join TV_ITASSIGN n on a."EXAM_KEY" = n."EXAM_KEY"
join TV_LABITEM ln on n."EVIDENCE_CONTROL_NUMBER" = ln."EVIDENCE_CONTROL_NUMBER"
join TV_LABNAME Lname ON p."NAME_KEY"=Lname."NAME_KEY"
WHERE "LAB_CASE"='10-000747';
This works fine
But when I executed 2nd query, I have 2 results
Blood
Blood
For the first query it is
Smith Jones
When I combine I get "Smith Jones " Blood.
But I should get 2 rows with the same name and Type "Blood" -
Hi,
Is there any difference in the below queries :
SELECT * from test left outer join test1 on test.col1 = test1.col1 and test.col1 = 2;
and
SELECT * from test left outer join test1 on test.col1 = test1.col1 where test.col1 = 2;
Please advise,
Thanks,
SmithaBut I don't know why they are diff.In the first version the test on COL2 is included in the OUTER JOIN syntax, which means it filters the result set differently....
SQL> CREATE TABLE test (col1 number, col2 number)
2 /
Table created.
SQL> CREATE TABLE test1 (col1 number, col2 number)
2 /
Table created.
SQL> INSERT INTO test VALUES (1, 1)
2 /
1 row created.
SQL> INSERT INTO test VALUES (1, 2)
2 /
1 row created.
SQL> INSERT INTO test VALUES (2, 2)
2 /
1 row created.
SQL> INSERT INTO test1 VALUES (1, 2)
2 /
1 row created.
SQL> SELECT * from test left outer join test1 on test.col1 = test1.col1 and test.col1 = 2;
COL1 COL2 COL1 COL2
1 1
1 2
2 2
SQL> SELECT * from test left outer join test1 on test.col1 = test1.col1 where test.col1 = 2;
COL1 COL2 COL1 COL2
2 2
SQL> SELECT * from test right outer join test1 on test.col1 = test1.col1 where test.col1 = 2
2 /
no rows selected
SQL> SELECT * from test right outer join test1 on test.col1 = test1.col1 and test.col1 = 2
2 /
COL1 COL2 COL1 COL2
1 2
SQL>
SQL>Cheers, APC -
Oracle outer join on multiple tables throws error
Hi ,
We are using ansi joins with outer joins on multiple tables in oracle 9i.
Now these queries have to be used in Oracle8i.
Since Oracle8i does not support ansi sql we are replacing the ansi sql queries with the oracle joins.
On trying the same we found that the following query
select *from tab1 a, tab2 b, tab3 c where a.c1 = b.col1(+) and c.c2 = b.col2 (+)
throws the error
ORA-01417: a table may be outer joined to at most one other table.
Is there a way to simulate this query without using the outer joins on multiple tables?
thanksTry writing the query in this form:
select * from
(select t1.col1, t1.col2
from schema.table1 t1, schema.table2 t2
where t1.col1 = t2.col1(+)) t4,
schema.table3 t3 where t4.col2 = t3.col2(+)
In the subquery, you will have to list all the columns you want to see, and you will need to provide unique aliases for any columns with duplicate names. I tested this on 9i, and don't have an 8i system to work with, so I hope this helps. -
Convert Joins from SQL Server to Oracle
I am converting a client application's back end from using SQL Server to Oracle. This application provides a GUI that allows people to capture one or more areas of text in a text file and create database tables from these areas. It allows them to perform joins between the tables, etc. I have to convert the area that programatically creates queries behind the scenes to do these joins. Having not done much work with Oracle joins, I'm wondering if someone could show me how I could convert the sample join provided. I can probably handle the rest from there.
SQL Server Query:
SELECT
[T1].[Tk] AS [Tk],
[T1].[Tk Title] AS [Tk Title],
[T2].[Rate] AS [Rate],
[T1].[TotCurHrs] AS [TotCurHrs],
[T1].[TotCurAmt] AS [TotCurAmt],
[T1].[TotCaseHrs] AS [TotCaseHrs],
[T1].[TotCaseAmt] AS [TotCaseAmt],
[T3].[SortF] AS [SortF]
FROM
[T1] FULL JOIN [T2] ON [T1].[Tk] = [T2].[TKName]
INNER JOIN [T3] ON [T1].[Tk Title] = [T3].[EliteTitle]
)Do as previous colleagues suggested, although you may get the problem with column names. I see at leats one of them has space in it [Tk Title]. So the question is - how you migrated table structure to Oracle? Do the column names are ABSOLUTELY the same as in MS? Then you have to replace brackets with double quotes ", because normally Oracle all identifiers tries to convert to uppercase and also space is not allowed. Only if you use quotes this is possible.
Gints Plivna
http://www.gplivna.eu
Edited by: gintsp on Oct 13, 2010 4:04 PM -
Searching for differences between oracle 8i and 9i
hello
can somebody help me please. i am searching for the difference between oracle 8i and 9i, and specially the differences in the DDL between 8i and 9i. may someone can help me!
thanks
Message was edited by:
Da Rookeei need some expamples to show the difference....for
example how it is written in 8i without joins and inNow you are talking about DML not DDL
For some examples showing the differences between the "traditional" Oracle join syntax and the ANSI join syntax see this article on oracle-base
http://www.oracle-base.com/articles/9i/ANSIISOSQLSupport.php -
Oracle Parsing SQL Statement in ANSI or Oracle Format
I have problem with a Query ..It seems to be Oracle Bugs .
When I enter below simple Query (in Oracle Join format ), It works properly
select * from (
select dept.*,emp.ename from dept,emp
where dept.deptno=emp.deptno(+)
where deptno in
select deptno a from
select deptno,dname from dept where deptno=10
UNION ALL
select deptno,dname from dept where deptno=20
But When I changed it and use it in ANSI Format ,it is not parsed and shows me ORA-00920: invalid relational operator error ......
Below shows the changes that I have made to convert it to ANSI Format.
select * from (
select dept.*,emp.ename from dept
left outer join emp on (emp.deptno=dept.deptno)
where (deptno) in
select deptno a from
select deptno,dname from dept where deptno=10
UNION ALL
select deptno,dname from dept where deptno=20
It seems to be Oracle bugs.I appreciate everybody to help me.
( Comments : I use Oracle 9i R2 on Windows and I can not change the SQL statement
because it is created dynamically)
Best regardsThis sort of technical question needs to be addressed to one of the technical forums. Products | Database | SQL and PL/SQL would seem to be appropriate here.
Have you tried applying the latest patchset for your database? Seems to work for me on 9.2.0.5
SCOTT @ HP92 Local> select * from (
2 select dept.*,emp.ename from dept
3 left outer join emp on (emp.deptno=dept.deptno)
4 )
5 where (deptno) in
6 (
7 select deptno a from
8 (
9 select deptno,dname from dept where deptno=10
10 UNION ALL
11 select deptno,dname from dept where deptno=20
12 )
13 )
14 /
DEPTNO DNAME LOC ENAME
10 ACCOUNTING NEW YORK CLARK
10 ACCOUNTING NEW YORK KING
10 ACCOUNTING NEW YORK MILLER
20 RESEARCH DALLAS SMITH
20 RESEARCH DALLAS JONES
20 RESEARCH DALLAS SCOTT
20 RESEARCH DALLAS ADAMS
20 RESEARCH DALLAS FORD
8 rows selected.
SCOTT @ HP92 Local> select * from v$version;
BANNER
Oracle9i Enterprise Edition Release 9.2.0.5.0 - Production
PL/SQL Release 9.2.0.5.0 - Production
CORE 9.2.0.6.0 Production
TNS for 32-bit Windows: Version 9.2.0.5.0 - Production
NLSRTL Version 9.2.0.5.0 - ProductionJustin
Distributed Database Consulting, Inc.
http://www.ddbcinc.com/askDDBC -
Flow accept error when using ANSI join syntax
Hi
I had a region populated by a query joining two views (one in-line using connect by). When trying to create the region if the join was coded using ANSI syntax (INNER JOIN .... USING) I got a flow accept error when either trying to proceed using the wizard, or apply changes when editing the region.
After changing to the old style Oracle join (using predicates), I was able to create the region and everything worked ok. I found the solution after reading this post Error 404 wwv_flow.accept was not found in which the OP says he would raise a bug. Did the bug get raised? I ask since his problem arose whilst he was selecting from a view using ANSI joins and using instead of triggers, and I was joining an in-line view to a view using ANSI joins and instead of triggers, but neither view has been changed, just the join syntax. The view defined in the database is used in other regions and works fine. This could indicate the OP's problem was fixed, but one still exists.
Incidentally this is the only time I have used non-ANSI joins in the entire apex app - the rest work!. Unfortunately it is impossible for me to demo the app.
Richard
using ApEx 3.0.1.00.07 and 10g (10.2.0.1) EE on WintelTyler,
Apologies, what I was trying to say was that I couldn't put the application on the Oracle APEX site.
Yes, I do have a work-around, but that does not mean a bug may still exist. I count myself fortunate I saw that post and, therefore, experimented with the syntax of the join - there is no reason APEX should not accept ANSI join conditions, in fact , it does. The ANSI-joined SQL statement executed perfectly in TOAD and SQL*Plus, but I could not even save it in APEX.
regards
Richard -
Left Outer Joining multiple tables to one source table FAILS with VLD-1511
Hi all,
Is it me, or is OWB unable to handle left outer joining 1 source table to multiple other tables?
I want to load a fact table so I have 1 source table with measures. This table must be outer joined to some dimensions that have their FK in the fact table.
The SQL statement would look like this (and is perfectly valid):
select ...
from input, dim1, dim2
where input.c1 = dim1.c1(+)
and input.c2 = dim2.c2(+);
I put the where clause in the joiner operator and validate, but that gives me message VLD-1511: A table may be outer joined to at most one other table.
Even splitting this up into one outer join per joiner still gives this message.
A search and look around on the forum and on metalink shows there are related issues (like bug 3334035). Seemingly creating a view is the work-around to use.....? (ie downgrading owb to a simple gui tool) }-;
Have other people experienced this problem of not being able to outer join one input table to multiple other tables?
Thanks,
EdI have had some feedback from Oracle. It turns out this has to do with 2 issues. Below I have pasted the text that Support gave me:
<---------- START QUOTE ---------->
RESEARCH
=========
Bug 3437036 KEY LOOKUP DOES NOT DETECT ORA-1417 IN VALIDATE/GENERATE STEP
Unpublished Bug 4211684 FORWARD PORT OF BUG 3437036
shows:
Some more development has been completed when this bug is fixed in Paris.
The following are the details:
1. If the join condition contains a full outer join such as
tab1.c (+) = tab2.c (+) and tab2.c (+) = tab3.c
then the new validations implemented for this bug do not apply since
in OWB, full outer join triggers generation of joins in ANSI syntax.
ANSI syntax does not have the original problem the base bug of this
bug reported.
2. If the join condition does not contain any full outer join condition,
then the join is generated in Oracle join syntax, which is subject two
several restrictions. The fix to this bug check two of the restrictions.
3. The first restriction in Oracle syntax is that the outer join operator
"(+)" can only directly be attached to a column name. If you attach it
to an expression, such as the following:
(tab1.c + 1) (+) = tab2.c
Then there will be an ORA-936 error at the time of mapping deployment.
For this case, I have added a validation message VLD-1512 to error out
this situation.
4. The second restriction in Oracle syntax is that a table can only be
outer joined to exactly one other table.
For example, this is an invalid join in Oracle syntax:
tab1.c (+) = tab2.c and tab1.d (+) = tab3.d
because tab1 is left outer joined to tab2 and tab3.
But note that the following is still valid in Oracle syntax:
tab1.c (+) = tab2.c and tab1.d = tab3.d (+)
because tab1 is left outer joined to tab2 and right outer joined to tab3.
So this latter case does not violate the restriction that "same oj" to
more than 1 table is not allowed.
If same oj to more than 1 table is specified in a join condition,
VLD-1511 will be issued, and the map is made invalid.
<---------- END QUOTE ---------->
OWB does a partial validation, ie not all access paths are (can be) checked. A full check is only done by the database itself. So some scenarios (like checking whether multiple tables are outer joined the correct way) are not checked, and in this case are flagged with an error (even though it is actually a correct scenario).
Seemingly this was not flagged with an error in earlier versions of OWB, so beware, OWB behaviour may change when upgrading...
Alternative solutions are (1) using key lookups, (2) using a view with all outer joins in there, (3) using intermediate result tables between the joins.
Hope this info helps some people prevent spending too much time on a false error message,
Ed -
I have a logical database design (3NF) with 19 joins to a base table. Realizing that joins are a performance killer, would it be advised to pull the joined values into the base table, place pre_insert and pre_update triggers on the base table to validate the data and remove the relationships to the 19 joined tables?
Joins are not a performance killer in Oracle. joining tables is what it is designed to do. As long as you have appropriate indexes on all of the tables to faclilitate the joins, you should not see much difference in performance between joining tables and de-normalizing your data. Have you actually benchmarked the time difference?
As Andrew points out, the perfomance of inserts and updates will suffer because of the triggers required for validation. Unless you are working in a huge data warehouse environment, I would stick with the normalized version.
You could also potentially run into integrity problems as well if you denormalize the data. What happens if someone deletes rows from one or more of the joined tables? You now have values in your base table that do not exist in the lookup tables.
HTH
John -
Hi,
Please try following example:
create table a (id integer, name varchar2(200));
create table b (id integer, nameb varchar2(200));
create view vv as select * from a where id < 100;
a) select name from a join vv on vv.id = a.id
this query will return ORA-00918: column ambiguously defined
b) select name
from a
join b on b.id = a.id
join vv on vv.id = a.id
this will return empty recordset without error. WHY?
If you place "join vv" before "join b" query WILL return the error
I know that i can:
- use classic oracle join syntax with WHERE clause
- use table name/alias in SELECT clause
but I'm not looking for the workaround. I'm just curious why Oracle works this way?
PS. i'm working on 10g
ptrYes indeed this is strange. I have created a small test setup.
SQL> create table a (id number, name varchar2(10))
2 /
Table created.
SQL> create table b (id number, name varchar2(10))
2 /
Table created.
SQL> create view v as select id, name || '-view' name from a
2 /
View created.
SQL> insert into a values(1,'karthick')
2 /
1 row created.
SQL> insert into b values(1,'karthick')
2 /
1 row created.
SQL> commit
2 /
Commit complete.
CASE 1
Now i join a and v alone. i get the ambiguous error as oracle does not know which name to select Name in table A or from view V.
SQL> select name
2 from a
3 join v
4 on a.id = v.id
5 /
select name
ERROR at line 1:
ORA-00918: column ambiguously defined
CASE 2
But see this, here oracle by itself decides that it will go with Name in View V.
SQL> select name
2 from a
3 join b
4 on a.id = b.id
5 join v
6 on a.id = v.id
7 /
NAME
karthick-view
CASE 3
But the same does not work with the oracle older version syntax.
SQL> select name
2 from a,b,v
3 where a.id = b.id
4 and a.id = v.id
5 /
select name
ERROR at line 1:
ORA-00918: column ambiguously definedSo the question is in CASE 2 how oracle decided to go with the View column. What made it to decide that. Is it a bug?
Thanks,
Karthick. -
I'm trying to use a Hierarchical Query with table joins in the "FROM" clause. According to the documentation, this will work with Oracle 9i and above.
My problem is that in some queries, using the "JOIN" syntax works correctly but in others, it gives an "ORA-00928" message.
If I change the query that gives the error to use old style Oracle joins (using the where clause), the query works.
Can anyone help me to identify the problem?Here's the query. Again, note that if I use the old oracle join syntax (using where clause) it works:
select level
, biu.parent_part_no
, biu.parent_part_serial_no
, biu.comp_part_qty
, cpi.part_no
, cpi.serial_number
, cpi.trace_code
from bom.bom_instance_usage biu
join bom.bom_part_instance cpi
on cpi.bom_part_instance_key = iu.comp_part_instance_key
start with ( biu.parent_part_no = '123456'
and biu.parent_part_serial_no = '114' )
connect by ( biu.parent_part_no = prior cpi.part_no
and biu.parent_part_serial_no = prior cpi.serial_number )
Maybe you are looking for
-
Hi, You have to follow following steps for MM; 1. MM02 - Material Master - Purchasing view Qual.f.FreeGoodsDis. enter here "1" i.e. Eligible for discount in kind for purchasing and sales 2. XK02 - Vendor Master - Purchasing view - Activate "Grant dis
-
Diagnosing cause of kernel panic on a Mac Pro
I've got an early 2009 Mac Pro with the following specs: 2.66 GHz Quad-Core Intel Xeon 16 GB 1066 MHz DDR3 ECC NVIDIA GeForce GT 120 512 MB OS X 10.8.1 Problem is, at random times, my Mac would just shut down and then restart after I clicked through
-
Inventory account not defined in item code
Hi, Iam trying to add A/p Credit memo from A/P invoice (Copy to method) and changing Unit price of one item (there 8 items) then it gives error of "Inventory account not defined item code" i check all accounts in Item group and Wh also.i also ch
-
BAPI_ACC_DOCUMENT_REV_CHECK
Hello, I´m using the bapi BAPI_ACC_DOCUMENT_REV_CHECK to check whether a FI document is able to be reversed. The bapi works fine, but it blocks the FI document till the programm finishes, so I can´t reverse the document if necesary. How can I unbl
-
TAKING LONG TIME TO APPROVE REQUISITIONS
Hi All Gurus we are noticing oracle procurement working much slower than normal lately. For example, when we are approving a PR, which we do through Edit Requisition, it's taking 20 or more seconds to go from screen to screen.can any has an Idea what