Solved

how to perform full outer join with + in oracle

Posted on 2014-12-28
5
205 Views
Last Modified: 2015-01-11
hi how can i do the full outer join in this sql using +
  WITH    by_parent    AS
    (
        SELECT    obj_parent
        ,         LISTAGG (obj_child, ',') WITHIN GROUP (ORDER BY obj_child)  AS obj_children
        FROM      cal_erd_link
        GROUP BY  obj_parent
    )
    ,    by_child    AS
    (
        SELECT    obj_child
        ,         LISTAGG (obj_parent, ',') WITHIN GROUP (ORDER BY obj_parent)  AS obj_parents
        FROM      cal_erd_link
        GROUP BY  obj_child
    )
    SELECT    NVL (p.obj_parent, c.obj_child)    AS obj_name
    ,         p.obj_children
    ,         c.obj_parents
    FROM             by_child   c
    FULL OUTER JOIN  by_parent  p  ON  p.obj_parent  = c.obj_child
    ;

Open in new window


am in 11gR2
0
Comment
Question by:chalie001
5 Comments
 
LVL 48

Accepted Solution

by:
PortletPaul earned 500 total points
ID: 40521006
Why would you want to? That's going backwards and most companies I know have already adopted to ANSI join syntax.

I don't allow any joins using + from anyone in my projects.
0
 
LVL 76

Expert Comment

by:slightwv (䄆 Netminder)
ID: 40521012
I agree with the above post:  Use ANSI if you can.

Since you want it anyway, see if this example helps:
drop table parent purge;
create table parent (id number);

drop table child purge;
create table child (id number, parent_id number);


insert into parent values(1);
insert into parent values(2);

insert into child values(1,1);
insert into child values(2,1);
insert into child values(3,2);
commit;


select p.id,c.id
from child c full outer join parent p on c.id=p.id
/

select p.id,c.id
from child c, parent p 
where c.id=p.id(+)
/

Open in new window

0
 
LVL 48

Expert Comment

by:PortletPaul
ID: 40521020
Without testing at all, the old equivalent for full outer join involves a UNION, along these lines:

SELECT    obj_name
,         p.obj_children
,         c.obj_parents
FROM ( 
      SELECT p.obj_parent as obj_name, p.obj_children, c.obj_parents
      FROM by_parent p, by_child c
      WHERE  p.obj_parent  = c.obj_child(+)
      UNION
      SELECT c.obj_child, p.obj_children, c.obj_parents
      FROM by_parent a, by_child b
      WHERE  p.obj_parent(+)  = c.obj_child
    )      

Open in new window


Even more reason to simply use the ANSI syntax :)
0
 
LVL 13

Expert Comment

by:Alexander Eßer [Alex140181]
ID: 40522627
I don't allow any joins using + from anyone in my projects.
Hell YES! Get rid of those proprietary Oracle syntax ASAP ;-)
There are numerous reasons coding ANSI style, and rather none for using Oracle's internal syntax :-((
0
 

Author Closing Comment

by:chalie001
ID: 40542949
its correct
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Problem with duplicate records in Oracle query 16 40
pl/sql - query very slow 26 71
SYS password changed. Now can't log in as SYS 27 28
Checking for column width 8 28
Have you ever had to make fundamental changes to a table in Oracle, but haven't been able to get any downtime?  I'm talking things like: * Dropping columns * Shrinking allocated space * Removing chained blocks and restoring the PCTFREE * Re-or…
This post first appeared at Oracleinaction  (http://oracleinaction.com/undo-and-redo-in-oracle/)by Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.
This video shows setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question