【问题标题】:Bulk Inserts with Oracle使用 Oracle 批量插入
【发布时间】: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


【解决方案1】:

t_emp_id 是RECORD 的集合。您需要在ith 索引处获取列的值。更改此语句

update employee  set status=2 where emp_id=t_emp_id(i); 

到

update employee  set status=2 where emp_id=t_emp_id(i).emp_id;

【讨论】:

    猜你喜欢
    • 2012-01-17
    • 2010-09-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-12
    • 1970-01-01
    • 1970-01-01
    • 2018-03-10
    相关资源
    最近更新 更多