dbTalk Databases Forums  

SELECT Question

comp.databases.oracle.server comp.databases.oracle.server


Discuss SELECT Question in the comp.databases.oracle.server forum.



Reply
 
Thread Tools Display Modes
  #61  
Old   
yossarian
 
Posts: n/a

Default Re: SELECT Question - 06-18-2008 , 03:15 AM






Mtek wrote:

Quote:
Quick question here, if I have a WHERE clause with an IN condition -
WHERE var IN (1, 2, 3)......

What if the list is dynamic? How would you do that?
Something along the lines of:

SQL> create type ListType as table of number ;
2 /

SQL> declare
2 ids ListType := ListType() ;
3 names owa_text.vc_arr ;
4 begin
5 ids.extend(3) ;
6 ids(1) := 102 ;
7 ids(2) := 104 ;
8 ids(3) := 110 ;
9 select
10 LAST_NAME
11 bulk collect into
12 names
13 from
14 table(cast(ids as ListType)) ids,
15 employees emp
16 where
17 emp.employee_id = ids.column_value
18 ;
19* end ;
20 /

PL/SQL procedure successfully completed.

Y.


Reply With Quote
  #62  
Old   
yossarian
 
Posts: n/a

Default Re: SELECT Question - 06-18-2008 , 03:15 AM






Mtek wrote:

Quote:
Quick question here, if I have a WHERE clause with an IN condition -
WHERE var IN (1, 2, 3)......

What if the list is dynamic? How would you do that?
Something along the lines of:

SQL> create type ListType as table of number ;
2 /

SQL> declare
2 ids ListType := ListType() ;
3 names owa_text.vc_arr ;
4 begin
5 ids.extend(3) ;
6 ids(1) := 102 ;
7 ids(2) := 104 ;
8 ids(3) := 110 ;
9 select
10 LAST_NAME
11 bulk collect into
12 names
13 from
14 table(cast(ids as ListType)) ids,
15 employees emp
16 where
17 emp.employee_id = ids.column_value
18 ;
19* end ;
20 /

PL/SQL procedure successfully completed.

Y.


Reply With Quote
  #63  
Old   
yossarian
 
Posts: n/a

Default Re: SELECT Question - 06-18-2008 , 03:15 AM



Mtek wrote:

Quote:
Quick question here, if I have a WHERE clause with an IN condition -
WHERE var IN (1, 2, 3)......

What if the list is dynamic? How would you do that?
Something along the lines of:

SQL> create type ListType as table of number ;
2 /

SQL> declare
2 ids ListType := ListType() ;
3 names owa_text.vc_arr ;
4 begin
5 ids.extend(3) ;
6 ids(1) := 102 ;
7 ids(2) := 104 ;
8 ids(3) := 110 ;
9 select
10 LAST_NAME
11 bulk collect into
12 names
13 from
14 table(cast(ids as ListType)) ids,
15 employees emp
16 where
17 emp.employee_id = ids.column_value
18 ;
19* end ;
20 /

PL/SQL procedure successfully completed.

Y.


Reply With Quote
  #64  
Old   
yossarian
 
Posts: n/a

Default Re: SELECT Question - 06-18-2008 , 03:15 AM



Mtek wrote:

Quote:
Quick question here, if I have a WHERE clause with an IN condition -
WHERE var IN (1, 2, 3)......

What if the list is dynamic? How would you do that?
Something along the lines of:

SQL> create type ListType as table of number ;
2 /

SQL> declare
2 ids ListType := ListType() ;
3 names owa_text.vc_arr ;
4 begin
5 ids.extend(3) ;
6 ids(1) := 102 ;
7 ids(2) := 104 ;
8 ids(3) := 110 ;
9 select
10 LAST_NAME
11 bulk collect into
12 names
13 from
14 table(cast(ids as ListType)) ids,
15 employees emp
16 where
17 emp.employee_id = ids.column_value
18 ;
19* end ;
20 /

PL/SQL procedure successfully completed.

Y.


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.