这个 PLSQL 代码块有什么问题
从批处理文件执行时,下面的代码块不会运行。它只是挂起(什么也没有发生)。它在那里坐了几个小时。我无法跟踪问题是什么或如何调试。请帮忙。
declare
v_personrefid varchar2(50);
v_hiredt date;
v_loaddt date;
v_personid number;
v1_personrefid varchar2(50);
v_seq number :=0;
cursor get_row is
select distinct personrefid from ARCHIVE_PERSON;
cursor get_row1 is
select
personrefid,
hiredt,
loaddt,
personid
from
ARCHIVE_PERSON
where
personrefid = v_personrefid
order by hiredt, loaddt;
begin
v_seq:=0;
open Get_row;
loop
fetch get_row into v_personrefid ;
exit when get_row%notfound;
begin
open get_row1;
loop
fetch get_row1 into v1_personrefid, v_hiredt, v_loaddt, v_personid;
exit when get_row1%NOTFOUND;
v_seq:= v_seq+1;
update ARCHIVE_PERSON
set version = v_seq
where
personrefid = v1_personrefid and
personid = v_personid and
hiredt = v_hiredt and
loaddt = v_loaddt;
commit;
end loop;
v_seq:=0;
close get_row1;
end;
end loop;
v_seq:=0;
close get_row;
end;
The code block below is not running when executed from a batch file. It just hangs (nothing happens). It sits there for hours. I am unable to track what the problem is or how to debug this. Please help.
declare
v_personrefid varchar2(50);
v_hiredt date;
v_loaddt date;
v_personid number;
v1_personrefid varchar2(50);
v_seq number :=0;
cursor get_row is
select distinct personrefid from ARCHIVE_PERSON;
cursor get_row1 is
select
personrefid,
hiredt,
loaddt,
personid
from
ARCHIVE_PERSON
where
personrefid = v_personrefid
order by hiredt, loaddt;
begin
v_seq:=0;
open Get_row;
loop
fetch get_row into v_personrefid ;
exit when get_row%notfound;
begin
open get_row1;
loop
fetch get_row1 into v1_personrefid, v_hiredt, v_loaddt, v_personid;
exit when get_row1%NOTFOUND;
v_seq:= v_seq+1;
update ARCHIVE_PERSON
set version = v_seq
where
personrefid = v1_personrefid and
personid = v_personid and
hiredt = v_hiredt and
loaddt = v_loaddt;
commit;
end loop;
v_seq:=0;
close get_row1;
end;
end loop;
v_seq:=0;
close get_row;
end;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一种可能是您的脚本中
end;
语句后面没有斜杠/
,这会告诉 SQLPlus 执行该块。如果您只是使用end;
后面什么都没有,SQLPlus 可能会等待更多它永远不会得到的输入。除此之外,我建议您的 dba 在块运行时查看
V$SESSION_WAIT
以查看您的会话正在等待什么。此外,您可以尝试如下重写,我认为这会更有效:
One possibility is that you don't have a slash
/
in your script following theend;
statement, which would tell SQLPlus to execute the block. If you simply haveend;
followed by nothing, SQLPlus may be waiting for more input that it will never get.Aside from that, I'd suggest having your dba look at
V$SESSION_WAIT
while the block is running to see what your session is waiting on.Moreover, you might try a rewrite like the following, which I think will be more efficient:
如果这确实是整个文件,则在最后的
end;
之后需要一个/
来告诉 SQL*Plus(假设这就是您用来运行批处理文件的内容)执行块。如果将其粘贴到 SQL*Plus 命令提示符中,您会看到它等待输入,并显示行号提示符。If that is really the entire file you need a
/
after the finalend;
to tell SQL*Plus (assuming that's what you're using to run the batch file) to execute the block. If you pasted that in to the SQL*Plus command prompt you'd see it waiting for input, displaying a line number prompt.