为什么 Oracle 中一个过程不能调用另一个过程
我在 Oracle 9i 中有 2 个过程(A,B)。就个人而言,它们都工作得很好。但我无法创建一个调用 A 的过程 C,A 又调用 B。我在 C 调用 A 之前、A 调用 B 之前以及 B 中的一个之前放置了 dbms_output.put_line 。不知何故,只有第一个 put_line 有效。这不起作用的可能原因是什么?谢谢你,
CREATE OR REPLACE PROCEDURE C (num in number)
as
begin
for r in (select col1 from Table1)
loop
dbms_output.put_line ('Inside C');
A(r.col1);
end loop;
end;
CREATE OR REPLACE PROCEDURE A (var1 IN varchar2)
AS
v1 varchar2;
cursor c1(c_var in varchar2) is
select col1 from table2 where col2=c_var;
BEGIN
open c1(var1);
loop
fetch c1 into v1;
exit when c1%notfound;
dbms_output.put_line ('Inside A');
B(v1);
end loop;
close c1;
END;
I have 2 procedures (A,B) in Oracle 9i. In individual, they all work fine. But I cannot make a procedure C that calls A, which in turn calls B. I put a dbms_output.put_line before C calls A, before A calls B and one in B. Somehow, only the first put_line works. What are the possible reasons why this doesn't work? Thank you,
CREATE OR REPLACE PROCEDURE C (num in number)
as
begin
for r in (select col1 from Table1)
loop
dbms_output.put_line ('Inside C');
A(r.col1);
end loop;
end;
CREATE OR REPLACE PROCEDURE A (var1 IN varchar2)
AS
v1 varchar2;
cursor c1(c_var in varchar2) is
select col1 from table2 where col2=c_var;
BEGIN
open c1(var1);
loop
fetch c1 into v1;
exit when c1%notfound;
dbms_output.put_line ('Inside A');
B(v1);
end loop;
close c1;
END;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
显然,游标 c1 为空,因此您的条件(当 c1%notfound 时退出)为 true,并且循环在 dbms_output 调用之前终止。
如果您想打印该行而不考虑空光标,请更改其位置,例如:
Obviusly, cursor c1 is empty, so your condition (exit when c1%notfound) is true and loop is terminated before the dbms_output call.
If you want to print the line regardless of a empty cursor, change it's position, for example:
尝试在 C 中放置一个异常处理程序来检测是否抛出异常;类似的东西
Try putting an exception handler in C to detect if an exception is being thrown; something like