【发布时间】:2020-03-31 07:52:34
【问题描述】:
在 PLSQL 块语句中,将执行 DML 操作。我将 FORALL 与 BULK COLLECT 一起使用。下面提到的PLSQL语句-
declare
v_sub tab_a%rowtype;
v_res varchar2(50);
type v_rec_tbl is table of tab_out%rowtype;
v_rec v_rec_tbl;
cursor C is select b.sid, a.sin, 'N', SYSDATE from tab_a a, tab_b b;
begin
open C;
fetch C bulk collect into v_rec limit 1000;
for i in (select a.sin from tab_a a, tab_b b where b.sid = .....)
loop
select * into v_sub from tab_a where sin = i.sin;
end loop;
FORALL i in v_rec.FIRST..v_rec.LAST
insert into tab_out
select b.sid, i.sin, 'N', SYSDATE from tab_a a, tab_b b where b.sid = ......;
commit;
close C;
end;
/
当我执行上面的 PL/SQL 语句时,在i.sin 中的insert into tab_out 行出现错误ORA-00904 和PLS-00487 为Invalid Identifier 和Invalid reference to variable 'i'。
我该如何解决这个错误,以便快速插入记录。
【问题讨论】:
-
如果你想让它更快,不要使用慢游标、循环或 PL/SQL
-
@a_horse_with_no_name 是的,我想让它更快,但在
FOR LOOP中让它变慢。有没有其他方法可以使这个 PLSQL 块语句更快。 -
然后彻底摆脱 PL/SQL 和 FOR 循环
标签: sql oracle plsql bulkinsert