存储过程打印详细异常

 1     --1.通过RAISE弹出框(调试时使用)  
 2     --2.通过sqlcode , sqlerrm 这两个内置变量来查看,例如:  
 3       
 4     DECLARE   
 5     --声明异常  
 6       some_kinds_of_err EXCEPTION;  -- Exception to indicate an error condition  
 7       
 8       v_ErrorCode NUMBER;           -- Variable to hold the error message code  
 9       v_ErrorText VARCHAR2(200);    -- Variable to hold the error message text  
10       
11     BEGIN   
12     --...  
13     --抛出异常  
14       IF ( ... ) THEN --(括号内填抛出异常的条件)  
15         RAISE some_kinds_of_err;  
16       END IF;  
17     --...  
18     EXCEPTION  
19     --捕捉异常  
20       WHEN some_kinds_of_err THEN  
21         /* do something to  Handler the errors */  
22      null;  
23     --捕捉其他异常,并获得 捕获异常的内容  
24         WHEN OTHERS THEN  
25         v_ErrorCode := SQLCODE;  
26         v_ErrorText := SUBSTR(SQLERRM, 1, 200);    
27     -- Note the use of SUBSTR here.  
28       
29     dbms_output.put_line(v_ErrorCode || '::'||v_ErrorText);  
30     END;  
31       
32       
33     /**  
34     sqlcode 就是错误代码  
35     sqlerrm 就是sql错误信息。注意用substr来截取,否则输出很难看。   
36       
37     **/  
原文地址:https://www.cnblogs.com/lowerCaseK/p/procedure_Exception.html