即使我使用 "table" 运算符也得到 "local collection types not allowed in SQL statements"
Getting "local collection types not allowed in SQL statements" even though I use "table" operator
我有一个过程,我正在尝试在 where 语句中使用一个集合。
procedure purge_table is
type t_ids is table of number;
arr_ids t_ids ;
begin
select distinct (s.id) bulk collect
into arr_ids
from students s;
select count(*)
into v_deleted_row_count
from students s
where s.id in (select * from table(arr_ids));
end;
我得到 "local collection types are not allowed i SQL statements" 包含 where 语句的行。
据我所知,我搜索了错误我的语法是正确的,但我不明白是什么
"Assuming that your collection is defined in SQL, not just in PL/SQL, you can use the TABLE operator "
在此处接受的答案中提到:Array in IN() clause oracle PLSQL.
这里也是接受的答案
建议和我一样。
我想这一定与在SQL中定义一个集合有关。你能帮我吗?
类型应在 SQL 级别创建,然后在您的 PL/SQL 过程中使用。像这样(基于 Scott 的架构):
SQL> set serveroutput on
SQL> create or replace type emp_tab as table of number;
2 /
Type created.
SQL> create or replace procedure purge_table is
2 arr_ids emp_tab := emp_tab();
3 v_deleted_row_Count number;
4 begin
5 select distinct (s.empno) bulk collect
6 into arr_ids
7 from emp s where deptno = 10;
8
9 select count(*)
10 into v_deleted_row_count
11 from emp s where s.empno in (select * from table(arr_ids));
12
13 dbms_output.put_line('Number = ' || v_deleted_row_count);
14 end;
15 /
Procedure created.
SQL> exec purge_table;
Number = 3
PL/SQL procedure successfully completed.
SQL>
我有一个过程,我正在尝试在 where 语句中使用一个集合。
procedure purge_table is
type t_ids is table of number;
arr_ids t_ids ;
begin
select distinct (s.id) bulk collect
into arr_ids
from students s;
select count(*)
into v_deleted_row_count
from students s
where s.id in (select * from table(arr_ids));
end;
我得到 "local collection types are not allowed i SQL statements" 包含 where 语句的行。 据我所知,我搜索了错误我的语法是正确的,但我不明白是什么 "Assuming that your collection is defined in SQL, not just in PL/SQL, you can use the TABLE operator " 在此处接受的答案中提到:Array in IN() clause oracle PLSQL.
这里也是接受的答案
建议和我一样。
我想这一定与在SQL中定义一个集合有关。你能帮我吗?
类型应在 SQL 级别创建,然后在您的 PL/SQL 过程中使用。像这样(基于 Scott 的架构):
SQL> set serveroutput on
SQL> create or replace type emp_tab as table of number;
2 /
Type created.
SQL> create or replace procedure purge_table is
2 arr_ids emp_tab := emp_tab();
3 v_deleted_row_Count number;
4 begin
5 select distinct (s.empno) bulk collect
6 into arr_ids
7 from emp s where deptno = 10;
8
9 select count(*)
10 into v_deleted_row_count
11 from emp s where s.empno in (select * from table(arr_ids));
12
13 dbms_output.put_line('Number = ' || v_deleted_row_count);
14 end;
15 /
Procedure created.
SQL> exec purge_table;
Number = 3
PL/SQL procedure successfully completed.
SQL>