Home » SQL & PL/SQL » SQL & PL/SQL » inner query use outer query (oracle 11g)
inner query use outer query [message #636402] Wed, 22 April 2015 15:03 Go to next message
miroconnect@yahoo.com
Messages: 202
Registered: April 2006
Senior Member


select 
*
from (
select 
(select 'col1' from dual  where  1=dp_params.days_pending  ) as col1,
(select sum(day) from (

select '1'  as day from dual  /*where 1=dp_params.days_pending*/ 
union
select '2'  as day from dual  /*where 1=dp_params.days_pending*/
)
) as col2  
from dual qu,
(select 1 as days_pending from dual )  dp_params  )


this is my query , I trying to explain my problem using simple dual select, In reality all the simple dual selects are complex one.


(select sum(day) from (

select 1  as day from dual  /*where 1=dp_params.days_pending*/ 
union
select 2  as day from dual  /*where 1=dp_params.days_pending*/
)
) as col2  




in this inner query I want to use the dp_params.days_pending , is there any way I can refer to days_pending in inner query? I commented out where condition which needs filed from outer query
Re: inner query use outer query [message #636406 is a reply to message #636402] Wed, 22 April 2015 22:35 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
SQL> WITH dp_params 
     AS (SELECT 1 AS days_pending 
         FROM   dual) 
SELECT * 
FROM   (SELECT (SELECT 'col1' 
                FROM   dual 
                WHERE  1 = dp_params.days_pending) AS col1, 
               (SELECT SUM(day) 
                FROM   (SELECT '1' AS day 
                        FROM   dual /*where 1=dp_params.days_pending*/ 
                        UNION 
                        SELECT '2' AS day 
                        FROM   dual /*where 1=dp_params.days_pending*/ 
                       ))                          AS col2 
        FROM   dual qu, 
               dp_params) 
  2    3    4    5    6    7    8    9   10   11   12   13   14   15   16   17  
SQL> /

COL1       COL2
---- ----------
col1          3


Re: inner query use outer query [message #636420 is a reply to message #636406] Thu, 23 April 2015 11:03 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
You're welcome!
Re: inner query use outer query [message #636426 is a reply to message #636420] Thu, 23 April 2015 12:34 Go to previous messageGo to next message
Michel Cadot
Messages: 68776
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator

Steady behavior, he is in my kill file...

Re: inner query use outer query [message #636441 is a reply to message #636426] Fri, 24 April 2015 01:34 Go to previous message
Lalit Kumar B
Messages: 3174
Registered: May 2013
Location: World Wide on the Web
Senior Member
Michel Cadot wrote on Thu, 23 April 2015 23:04

Steady behavior, he is in my kill file...



He never comes back!

http://www.orafaq.com/forum/m/578208/#msg_578208
http://www.orafaq.com/forum/m/552992/#msg_552992
http://www.orafaq.com/forum/m/552980/#msg_552980
http://www.orafaq.com/forum/m/552986/#msg_552986
http://www.orafaq.com/forum/m/587996/#msg_587996
http://www.orafaq.com/forum/m/614104/#msg_614104
Previous Topic: complex view query with multiple lookups
Next Topic: Reading the Highvalue of partition and performing dynamic operation
Goto Forum:
  


Current Time: Mon Aug 03 02:26:12 CDT 2026