我有一个由整数索引的整数关联数组,我希望能够在select的where子句中使用它。类似的东西:
TYPE myAssocArray IS TABLE OF PLS_INTEGER NOT NULL INDEX BY PLS_INTEGER; SELECT * FROM MyTable WHERE MyTable_Column IN (SELECT * FROM TABLE(myAssocArray.keys))
和价值观相同。 据我所知,这不是直接可能的,因为关联数组不是SQL类型。有没有正确的方法来解决这个限制? 提前感谢所有建议!
答案 0 :(得分:0)
创建sql级嵌套表集合。并将密钥从AssocArray复制到集合中。
create type l_number is table of number;
declare
TYPE myAssocArray IS TABLE OF PLS_INTEGER NOT NULL INDEX BY PLS_INTEGER;
arr myAssocArray;
vKey PLS_INTEGER;
keys_list l_number := l_number();
begin
arr(1) := 1;
arr(5) := 1;
arr(6) := 1;
vKey := arr.first();
while vKey is not null loop
keys_list.extend(1);
keys_list(keys_list.count) := vKey;
vKey := arr.next(vKey);
end loop;
for rec in ( select column_value from table(keys_list)) loop
dbms_output.put_line(rec.column_value);
end loop;
end;