ORACLE 存储过程异常捕获并抛出

来源:互联网 发布:华帝油烟机怎么样知乎 编辑:程序博客网 时间:2024/05/30 23:03

DECLARE   

--声明异常  
  some_kinds_of_err EXCEPTION;  -- Exception to indicate an error condition  
  v_ErrorCode NUMBER;           -- Variable to hold the error message code  
  v_ErrorText VARCHAR2(200);    -- Variable to hold the error message text  
BEGIN   
--...  
--抛出异常  
  IF ( ... ) THEN --(括号内填抛出异常的条件)  
    RAISE some_kinds_of_err;  
  END IF;  
--...  
EXCEPTION  
--捕捉异常  
  WHEN some_kinds_of_err THEN  
    /* do something to  Handler the errors */  
 null;  
--捕捉其他异常,并获得 捕获异常的内容  
    WHEN OTHERS THEN  
    v_ErrorCode := SQLCODE;  
    v_ErrorText := SUBSTR(SQLERRM, 1, 200);    
-- Note the use of SUBSTR here.  
  
dbms_output.put_line(v_ErrorCode || '::'||v_ErrorText);  
END;  
  

原创粉丝点击