PLSQL使用SQLCODE和SQLERRM的小例子

开始

SET SERVEROUTPUT ON;



DECLARE 

  v_ename emp.ename%TYPE;

  e_norecord EXCEPTION;

  PRAGMA EXCEPTION_INIT (e_norecord, -20001);



  err_num NUMBER;

  err_msg VARCHAR2(100);



BEGIN

  

  SELECT ename INTO v_ename FROM emp WHERE empno=3000; 



EXCEPTION

  WHEN OTHERS THEN

      err_num := SQLCODE;

      err_msg := SUBSTR(SQLERRM, 1, 100);

      DBMS_OUTPUT.PUT_LINE(err_num||'----'||err_msg);

END;

运行结果:

anonymous block completed

100----ORA-01403: no data found

结束

你可能感兴趣的:(plsql)