0

我有如下代码:

DECLARE
rec emp%ROWTYPE
BEGIN
<<start_again>>
FOR rec IN c1 LOOP
    SELECT emp_index
    INTO   flag
    FROM   m_sme006
    WHERE  emp_id = rec.emp_id
           AND eff_dt = rec.eff_dt
           AND end_dt = rec.end_dt
           AND last_maint_ts > rec.last_maint_ts;
END LOOP;
EXCEPTION
    WHEN no_data_found THEN
      GOTO start_again;
END; 

每次发生 no_data_found 异常时,我都希望执行返回并继续下一次迭代。但它抛出error PLS-00375: illegal GOTO statement

我也可以将此行包含dbms_output.Put_line('Outside exception block'rec.sme006_index);在异常块中以查看发生的位置吗?

提前致谢

4

2 回答 2

1

您不能将程序流从异常块返回到执行块。您需要将异常块放入循环中,如下所示:

DECLARE
   rec emp%ROWTYPE
BEGIN
FOR rec IN c1 LOOP
    BEGIN
       SELECT emp_index
       INTO   flag
       FROM   m_sme006
       WHERE  emp_id = rec.emp_id
              AND eff_dt = rec.eff_dt
              AND end_dt = rec.end_dt
              AND last_maint_ts > rec.last_maint_ts;
    EXCEPTION
       WHEN no_data_found THEN
          dbms_output.Put_line('Outside exception block ' || rec.sme006_index);
    END;
END LOOP;
END;
于 2013-01-08T20:23:29.390 回答
0

我相信你正在寻找这样的东西:

DECLARE
  rec emp%ROWTYPE
BEGIN
  FOR rec IN c1 LOOP
    BEGIN
        SELECT emp_index
        INTO   flag
        FROM   m_sme006
        WHERE  emp_id = rec.emp_id
           AND eff_dt = rec.eff_dt
           AND end_dt = rec.end_dt
           AND last_maint_ts > rec.last_maint_ts;
    EXCEPTION
        WHEN no_data_found THEN
          -- whatever code you want to log your error
    END;
  END LOOP;
END; 
于 2013-01-08T20:22:44.673 回答