我是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:数据类型不一致:预期的数量为SYS_PLSQL_22223_23_1
谢谢你的帮助!
不,不能以这种方式完成。使用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