PLSQL:ORA- 00904 错误 "Invalid identifier" & PLS- 00487 错误作为无效标识符和对变量的无效引用 'i'
PLSQL: ORA- 00904 err "Invalid identifier" & PLS- 00487 error as Invalid Identifier & Invalid reference to variable 'i'
在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
as Invalid Identifier
& Invalid reference to variable 'i'
。
我怎样才能解决这个错误,以便快速插入记录。
是v_rec(i).sin
,不是i.sin
。
不过,您是说您希望 运行 更快。您为什么选择 变慢 的方法?您使用游标、循环……等等。
直接插入行,不涉及PL/SQL(除非必要):
insert into tab_out (sid, sin, ...)
select b.sid, i.sin, ...
from tab_a a join tab_b b on ...
where ... ;
您必须按如下方式使用集合 v_rec
上的索引:
FORALL idx in 1..v_rec.COUNT -- changes here
insert into tab_out
select b.sid, v_rec(idx).sin, 'N', SYSDATE from tab_a a, tab_b b where b.sid = ......;
-- see the usage of the idx
在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
as Invalid Identifier
& Invalid reference to variable 'i'
。
我怎样才能解决这个错误,以便快速插入记录。
是v_rec(i).sin
,不是i.sin
。
不过,您是说您希望 运行 更快。您为什么选择 变慢 的方法?您使用游标、循环……等等。
直接插入行,不涉及PL/SQL(除非必要):
insert into tab_out (sid, sin, ...)
select b.sid, i.sin, ...
from tab_a a join tab_b b on ...
where ... ;
您必须按如下方式使用集合 v_rec
上的索引:
FORALL idx in 1..v_rec.COUNT -- changes here
insert into tab_out
select b.sid, v_rec(idx).sin, 'N', SYSDATE from tab_a a, tab_b b where b.sid = ......;
-- see the usage of the idx