像这样?
SQL> create type numbers as table of number;
2 /
Type created.
SQL> create table foo (id number) ;
Table created.
SQL> insert into foo select rownum from dual connect by level <= 10;
10 rows created.
SQL> select * from foo;
ID
----------
1
2
3
4
5
6
7
8
9
10
10 rows selected.
SQL> create procedure testnum(p_num in numbers)
2 is
3 begin
4 for r_row in (select id
5 from foo f
6 where f.id in (select /*+ cardinality(t, 10) */ column_value
7 from table(p_num) t))
8 loop
9 dbms_output.put_line(r_row.id);
10 end loop;
11 end;
12 /
Procedure created.
SQL> set serverout on
SQL> exec testnum(numbers(2, 6, 9));
2
6
9
基数提示用于大致告诉 oracle 表中有多少元素。没有它,Oracle 将假定大约 8k 行,这可能太高并导致计划中不需要的完整扫描。
如果您愿意,也可以直接加入。
for r_row in (select /*+ cardinality(t, 10) */ f.id
from foo f
inner join table(p_num) t
on t.column_value = f.id)