这个 PLSQL 代码块有什么问题

发布于 2025-01-04 04:43:17 字数 942 浏览 0 评论 0原文

从批处理文件执行时,下面的代码块不会运行。它只是挂起(什么也没有发生)。它在那里坐了几个小时。我无法跟踪问题是什么或如何调试。请帮忙。

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

爱给你人给你 2025-01-11 04:43:17

一种可能是您的脚本中 end; 语句后面没有斜杠 /,这会告诉 SQLPlus 执行该块。如果您只是使用 end; 后面什么都没有,SQLPlus 可能会等待更多它永远不会得到的输入。

除此之外,我建议您的 dba 在块运行时查看 V$SESSION_WAIT 以查看您的会话正在等待什么。

此外,您可以尝试如下重写,我认为这会更有效:

DECLARE
  CURSOR my_cur IS
    SELECT ROW_NUMBER() OVER (PARTITION BY personrefid ORDER BY hiredt, loaddt) seq
      FROM archive_person
      FOR UPDATE;
BEGIN
  FOR my_rec IN my_cur LOOP
    UPDATE archive_person SET version = my_rec.seq
      WHERE CURRENT OF my_cur;
  END LOOP;
END;
/

One possibility is that you don't have a slash / in your script following the end; statement, which would tell SQLPlus to execute the block. If you simply have end; 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:

DECLARE
  CURSOR my_cur IS
    SELECT ROW_NUMBER() OVER (PARTITION BY personrefid ORDER BY hiredt, loaddt) seq
      FROM archive_person
      FOR UPDATE;
BEGIN
  FOR my_rec IN my_cur LOOP
    UPDATE archive_person SET version = my_rec.seq
      WHERE CURRENT OF my_cur;
  END LOOP;
END;
/
满栀 2025-01-11 04:43:17

如果这确实是整个文件,则在最后的 end; 之后需要一个 / 来告诉 SQL*Plus(假设这就是您用来运行批处理文件的内容)执行块。如果将其粘贴到 SQL*Plus 命令提示符中,您会看到它等待输入,并显示行号提示符。

If that is really the entire file you need a / after the final end; 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文