是否可以定義將在光標選擇中使用的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