Oracle Procedure- 结束循环外的语句不执行

Oracle Procedure- Statements outside of End Loop not Executing

需要以下方面的帮助。结束循环后的语句未执行。结构如下:

Create or replace procedure a.xyz (b in varchar2,c in varchar2.....) is
  bunch of variable declaration

  cursor c1

begin
  open c1;

  loop
    fetch c1 into ....;
    exit when c1%notfound;

    insert
    insert
    merge
    merge
    commit;
  end loop;

  insert
  select into
  send email
exception
end;

插入,select 到,发送电子邮件未被执行。有线索吗?

您没有 post 过程中有趣的部分 - EXCEPTION 有什么作用?

这是您修改后的伪代码。阅读我写的评论。

Create or replace procedure a.xyz (b in varchar2,c in varchar2.....) is
  bunch of variable declaration

  cursor c1

begin
  open c1;
  loop
    begin                   --> inner begin - exception - end block
      fetch c1 into ....;
      exit when c1%notfound;

      insert
      insert
      merge
      merge
    exception
      when ... then ...     --> handle exceptions you expect. If you used
                            --  WHEN OTHERS THEN NULL, that'a usually a huge mistake.
                            --  Never use unless you're testing something,
                            --  without RAISE, or if you really don't care if
                            --  something went wrong
    end;                    --> end of inner block
  end loop;

  insert
  select into
  send email

  commit;                   --> commit should be out of the loop; even better,
                            --  you should let the CALLER to decide when and
                            --  whether to commit, not the procedure itself
exception
  when ... then ...
end;

内部 BEGIN-EXCEPTION-END 块 - 如果异常处理得当 - 将使 LOOP 结束执行。你应该记录你得到的错误(出于测试目的,它甚至可以

EXCEPTION
  WHEN OTHERS THEN
    dbms_output.put_line(c1.id ||': '|| sqlerrm);
END;

这样你就能真正看到哪里出了问题。如果只是

EXCEPTION
  WHEN OTHERS THEN NULL;
END;

不知道是否发生了错误,错误发生的位置和原因。