Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Efficient way to handle multiple outer joins

user7675104Mar 28 2014 — edited Mar 28 2014

I have a large refcursor that is currently being returned from a oracle 11g stored procedure.  I need to add a few addiotional columns to the record set before it is returned.   The logic to include the new columns is not simple and I will have to WITH statements to store the new columns.  In total, I will have the WITH containing the results that are currently being returned and 5 additional WITH statements that each contain an id column to join to the existing record set and the new column.  My question is, how would I left outer join the existing record set(with id column) with each of the 5 WITH statement queries to include the 5 new column in the original dataset?

example:

WITH orginalresults  AS (

    SELECT id,

                  col1,

                 col2

                ...

)

WITH newcol1 AS (

     Select id,

                 newcol1

)

WITH newcol2 AS (

     select id,

                newcol2

)

Join

select .*, newcol1.newcol1, newcol2.newcol2, newcol3.newcol3,newcol4.newcol4 .....

from orginalresults

left outer join newcol1 on orginalresults .id = newcol1.id

left outer join newcol2 on originalresults.id = newcol2.id

left outer join newcol3 on originalresults.id = newcol2.id

left outer join newcol4 on originalresults.id = newcol4.id

.....

I will have to repeat the joins five times.   Is this approach valid?  Is there a better way to do this?

This post has been answered by BrunoVroman on Mar 28 2014
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 25 2014
Added on Mar 28 2014
8 comments
759 views