using SQL type:
SQL> create type t_id is table of number; 2 / Type created. SQL> CREATE OR REPLACE PROCEDURE PROCEDURE1 2 as 3 v_ids t_id; 4 v_user_ids number; 5 BEGIN 6 7 -- fill variable v_id with id's, user_id is of type number 8 select user_id 9 bulk collect into v_ids 10 from user_users 11 where user_id between 100 and 120; 12 13 select user_id into v_user_ids 14 from user_users 15 where user_id in (select t.column_value from table(v_ids) t) 16 and rownum = 1; 17 18 dbms_output.put_line(v_user_ids); 19 20 END PROCEDURE1; 21 / Procedure created. SQL> exec procedure1 100
where cardinality(t, 10) should be a reasonable guess about how many elements are in your array.
Note: using unlimited volume collection, like you:
8 select user_id 9 bulk collect into v_ids 10 from user_users;
as a rule, it is small if your array can have many thousands or more lines, as you press too hard on the memory and eventually dump the code. You would be better off working with an explicit open x for .. cursor and bulk sampling in a loop with a limit clause, i.e. fetch x bulk collect into v_ids limit 100 , and process in batches, for example, 100-1000.
source share