是否可以定义将在光标选择中使用的id列表?PL/SQL:声明IN条件中要使用的数字列表
我试着做如下
DECLARE
insert_user_id number := 1;
type nt_type is table of number;
building_num nt_type := nt_type (1,2,3,4,5);
cursor curs1 is
(
select ID
from objects
where BUILDING_NUM in (building_num)
);
但是我得到的是以下错误:
PLS-00642: local collection types not allowed in SQL statements
我发现什么了,是,如果我将声明这样的数字列表,它将有可能通过它们来Loop
。但我不想要它。我想要的只是在游标的IN
条件内。
我该怎么办?
我想问我,为什么我只是不把光标内的IN
放在ID里面?我的答案是:我有几个使用相同列表ID的光标。
编辑:
根据下面的答案,代码看起来如下:
create type nt_type is table of number;
DECLARE
insert_user_id number := 1;
building_num nt_type := nt_type (1,2,3,4,5);
cursor curs1(building_nums nt_type) is
(
select ID
from objects
where BUILDING_NUM in (select * from table(building_nums))
);
一个可能的解决方案是声明,其中插入所需数量的名单表(或者一个临时表),然后编写查询参照表 – Carlo