Quote:
Originally posted by mchih
for example,
i will pass down a array of values( the total count of values varies)
and i will build a generic SQL:
select value
from test_table
where (value = arrary_of_values[1])
(value = arrary_of_values[2])
.
.
.
;
statement within the parenthesis is what i will need to construct, based on how many values are there.
Mark
|
Ah, that doesn't require dynamic SQL, but it uses some fancy stuff:
SQL> create type numtab_type as table of number;
2 /
Type created.
SQL> declare
2 array_of_values numtab_type := numtab_type( 51778, 41400, 38460 );
3 begin
4 for r in
5 ( select * from all_objects
6 where object_id in (select * from table(select cast(array_of_values as numtab_type) from dual))
7 )
8 loop
9 dbms_output.put_line(r.object_name);
10 end loop;
11* end;
SQL> /
EMP
DEPT
SALGRADE
PL/SQL procedure successfully completed.
As you can see, I queried from ALL_OBJECTS the 3 rows with OBJECT_IDs 51778, 41400 and 38460 which were stored in the array.
The array needs to be of a SQL type though (i.e. CREATE TYPE statement), it will not work with PL/SQL collections.