需要以下幫助。結束回圈后的陳述句未執行。結構如下:
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;
插入、選擇、發送電子郵件未執行。有什么線索嗎?
uj5u.com熱心網友回復:
您沒有發布程式中有趣的部分——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;
你不知道是否發生了一些錯誤,發生在哪里,為什么。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/428797.html
