0

我是 PL/SQL 的新手,我想知道是否可以像这样使用批量收集的结果:

Declare
type result_bulk_type is Table of table1.ID%type;
result_bulk result_bulk_type;
BEGIN
SELECT id BULK COLLECT INTO result_bulk FROM table1;
UPDATE table2 SET status=1 WHERE id IN result_bulk;
END;

我在编译时遇到错误:

PL/SQL:忽略 SQL 语句

PL/SQL:ORA-00932:不一致的数据类型:预期 NUMBER 得到 SYS_PLSQL_22223_23_1

谢谢你的帮助!

4

2 回答 2

2

不,不能以这种方式完成。请改用 FORALL 语句。
阅读:http

://docs.oracle.com/cd/B28359_01/appdev.111/b28370/forall_statement.htm#LNPLS01321 一个例子:

Declare
  type result_bulk_type is Table of table1.ID%type;
  result_bulk result_bulk_type;
BEGIN
  SELECT id BULK COLLECT INTO result_bulk FROM table1;
  FORALL i IN INDICES OF result_bulk
    UPDATE table2 SET status=1 WHERE id = result_bulk( i );
END;
/

演示: http ://sqlfiddle.com/#!4/b3a72/1

于 2014-02-13T13:59:25.023 回答
1

使用'where id MEMBER OF result_bulk'

于 2014-02-13T15:40:40.407 回答