需要基于集合值在where子句中添加条件。
create or replace type item_type force as object
(
key number(3),
value varchar2(20)
)
create or replace type item_coll force as table of item_type
create or replace type req_type force as object
(
rule varchar2(20),
items item_coll
)
procedure sample( in_a IN req_type, out_b OUT ret_coll)
as
select * bulk collect into out_b
from tab_test a
where a.rule= in_a.rule;
示例:
Input string : req_type('aaa',item_coll(item_type(1,'A'),item_type(2,'B'),item_type(3,'C')));
最终查询应该像
Select * bulk collect into out_b
from tab_test a
where a.rule= in_a.rule
and ((a.key = 1 and a.value = 'A') OR
(a.key = 2 and a.value = 'B') OR
(a.key = 3 and a.value = 'C'))
有人可以建议解决方案吗?
答案 0 :(得分:0)
也许还有其他方法,但这对我有用:
select item_type(a.key, a.value)
bulk collect into out_b
from tab_test a
where in_a.rule = a.rule
and (a.key, a.value) in (select key, value from table(in_a.items));
答案 1 :(得分:0)
select item_type(a.key, a.value)
bulk collect into out_b
from tab_test a
where in_a.rule = a.rule
and exists (select 'x'
from table(in_a.items) i
where a.key = i.key
and a.value = i.key);