Friday, June 11, 2010

Q: What are SQLCODE and SQLERRM and why are they important for PL/SQL developers?

[類別] PL/SQL
[問題] 什麼是SQLCODE與SQLERRM,為什麼他們對PL/SQL開發者而言很重要?

Answer:

SQLCODE與SQLERRM都是用在exception handler裡。

SQLCODE會回傳exception的號碼,SQLERRM則是錯誤訊息內容。
最常見的用法就是搭配WHER OTHERS EXCEPTION使用:

DECLARE

   v_code NUMBER;

   v_errm VARCHAR2(64);

BEGIN

   ………

EXCEPTION

   WHEN OTHERS THEN

        v_code := SQLCODE;

        v_errm := TO_CHAR(SQLERRM(v_code));

        DBMS_OUTPUT.PUTLINE(‘ERRCODE ’ || v_code);

        DBMS_OUTPUT.PUTLINE(‘ERRMSG ’ || v_errm);

END;

重要性? 當然是... 你可以處理exceptions,知道更詳細的訊息囉。

Comments

0 Responses to "Q: What are SQLCODE and SQLERRM and why are they important for PL/SQL developers?"

Post a Comment

Tags