我想将一个数字列表查询到一个 plsql 变量中,并在另一个 sql 查询的 in 子句中使用它。我在下面创建了一个我想要做的测试用例。
我为解决方案搜索了谷歌,我认为它一定是可能的,但我只是没有让它运行。请帮助我提供编译解决方案。
CREATE OR REPLACE PROCEDURE PROCEDURE1
as
type t_id is table of number;
v_ids t_id;
v_user_ids number;
BEGIN
-- fill variable v_id with id's, user_id is of type number
select user_id
bulk collect into v_ids
from user_users;
-- then at a later stage ... issue a query using v_id in the in clause
select user_id into v_user_ids from user_users
-- this line does not compile ( local collection type not allowed in SQL statements)
where user_id in ( v_ids );
END PROCEDURE1;