我是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
感谢您的帮助!
答案 0 :(得分: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;
/
答案 1 :(得分:1)
使用' WHERE id成员result_bulk'