【发布时间】:2017-11-20 12:11:58
【问题描述】:
我有一个包含 4800 条记录的表 EMPLOYEE,有两列 emp_id (1:4800) 和状态(所有记录均为 0)。 我正在实施批量收集,限制为 1000,因此对于每 1000 条记录,所有相应状态的收集状态都设置为 1。 这是我的代码
declare
TYPE bulk_emp_id is table of employee%rowtype;
t_emp_id bulk_emp_id := bulk_emp_id();
cursor c_emp is
select * from employee;
begin
open c_emp;
loop
fetch c_emp
bulk collect into t_emp_id limit 1000;
exit when t_emp_id.count=0;
forall i in t_emp_id.first..t_emp_id.last
update employee set status=2 where emp_id=t_emp_id(i);
COMMIT;
DBMS_OUTPUT.put_line(t_emp_id.count || ' rows');
end loop;
close c_emp;
end;
/
我收到一个错误
update employee set status=2 where emp_id=t_emp_id.emp_id(i);
PLS-00382:表达式类型错误
代码仅适用于 BULK COLLECT。
【问题讨论】:
-
为什么这么复杂?为什么不使用单个更新语句?
标签: oracle plsql plsqldeveloper