![](/img/trans.png)
[英]How to pass table as a parameter and populate that table using plsql procedure
[英]using plsql table in a procedure
我在oracle数据库9i中使用plsql我有一个存储过程,带有一个名为“数字表”的in参数,称为数字。 我现在想要从一个表中选择所有行,其中一个名为:ID的列等于“数字”内的数字就像我可以select * from table name where Id in (!,!,!,...)
谢谢寻求帮助。
更新:为了清理,我有一个名为numbers的用户定义类型,Number定义为:number of number。 所以在程序中,我有“P_array in numbers”我需要select * from a table where Id is found in p_array
像这样?
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)
尝试以下方法: -
select * from tableName where id in (select c.column_value from table(cast(p_array as numbers)) c);
其中数字是数字表
SELECT * FROM A_TABLE WHERE ID IN (SELECT SAVED_NUMBERs FROM TABLE_NUMBER);
你是说这个吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.