0

我在 Oracle 9i 中有 2 个过程(A,B)。就个人而言,它们都工作正常。但是我不能创建一个调用 A 的过程 C,而 A 又调用 B。我在 C 调用 A 之前放置了一个 dbms_output.put_line,在 A 调用 B 和 B 之前放置了一个。不知何故,只有第一个 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;
4

2 回答 2

2

显然,游标 c1 为空,因此您的条件(c1%notfound 时退出)为真,并且循环在 dbms_output 调用之前终止。

如果要打印该行而不考虑空光标,请更改其位置,例如:

CREATE OR REPLACE PROCEDURE C (num in number)
as
begin
    dbms_output.put_line ('Inside C');
    for r in (select col1 from Table1)
    loop
        dbms_output.put_line ('Calling A');
        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
    dbms_output.put_line ('Inside A');
    open c1(var1);
    loop
        fetch c1 into v1;
        exit when c1%notfound;
        dbms_output.put_line ('Calling B');
        B(v1);
    end loop;
    close c1;
END;
于 2010-10-26T23:50:53.750 回答
0

尝试在 C 中放置一个异常处理程序来检测是否抛出了异常;就像是

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;
EXCEPTION
  WHEN OTHERS THEN
    DBMS_OUTPUT.PUT_LINE('Exception caught in C : ' || SQLCODE || ' ' || SQLERRM);
    RAISE;
end;
于 2010-10-26T23:52:15.233 回答