SELECT语句中的Oracle 11g PLSQL集合
我在PLSQL begin块中有一个类型表集合,我不得不在代码中多次使用它 在SELECT语句中有没有使用列表(表类型)的方法? 我的目标是写更少的代码 我将数组(表)直接包含在SELECT语句中 下面的脚本显示了我要做的事情,但显然,我做不到,因为我们不能在SQL语句中使用集合(请检查delete语句)SELECT语句中的Oracle 11g PLSQL集合,select,plsql,collections,oracle11g,Select,Plsql,Collections,Oracle11g,我在PLSQL begin块中有一个类型表集合,我不得不在代码中多次使用它 在SELECT语句中有没有使用列表(表类型)的方法? 我的目标是写更少的代码 我将数组(表)直接包含在SELECT语句中 下面的脚本显示了我要做的事情,但显然,我做不到,因为我们不能在SQL语句中使用集合(请检查delete语句) 如果您使用oracle 12c,那么您应该能够使用带有表运算符的本地定义集合。e、 g Select * from table where column in(select col
如果您使用oracle 12c,那么您应该能够使用带有
表
运算符的本地定义集合。e、 g
Select *
from table
where column in(select column_value from table(PLACE_code_ls))
或者,您可以将集合创建为对象类型
create or replace type arrayList is table of varchar2(100);
然后在PLSQL块中使用它
DECLARE
...
PLACE_code_ls arrayList ; -- this is a new created global object type
...
BEGIN
code_grp := '454D';
PLACE_code_ls := arrayList ('ABVDE','ADE','EFEF','JHGJ','JHGJH');
DELETE CARP.assos_place_grp
WHERE CODE_GROUPE = code_grp AND CODE_PLACE NOT IN (SELECT S.CODE
FROM CARP.PLACE S
WHERE S.CODE_IMPLANTATION IN
(select column_value from table(PLACE_code_ls));
-- select from your collection
COMMIT;
END;
/
您不能像这样使用本地集合,但您可以使用
for all
,这很快,如以下所示:
declare
type tt is table of varchar2(5);
vt tt := tt('C', 'E', 'N', 'X');
begin
forall i in vt.first..vt.last
delete from test
where name = vt(i);
end;
您可以看到所有和。。。循环可能重复的
declare
type tt is table of varchar2(5);
vt tt := tt('C', 'E', 'N', 'X');
begin
forall i in vt.first..vt.last
delete from test
where name = vt(i);
end;