当前位置: 代码迷 >> SQL >> pl sql中如何避免错误
  详细解决方案

pl sql中如何避免错误

热度:51   发布时间:2016-05-05 12:49:04.0
pl sql中如何处理异常
点击右边红色标题查看本文完整版:pl sql中如何处理异常

pl sql中如何处理异常?

------解决方法--------------------
DECLARE
? v_ErrorCode NUMBER; ? ? -- Code for the error
? v_ErrorMsg VARCHAR2(200); -- Message text for the error
? v_CurrentUser VARCHAR2(8); -- Current database user
? v_Information VARCHAR2(100); -- Information about the error
? BEGIN
? /* Code which processes some data here */
? NULL;
? EXCEPTION
? WHEN OTHERS THEN
? ? -- Assign values to the log variables, using built-in
? ? -- functions.
? ? v_ErrorCode := SQLCODE;
? ? v_ErrorMsg := SQLERRM;
? ? v_CurrentUser := USER;
? ? v_Information := 'Error encountered on ' ||
? ? TO_CHAR(SYSDATE) || ' by database user ' || v_CurrentUser;
? ? -- Insert the log message into log_table.
? ? INSERT INTO log_table (code, message, info)
? ? VALUES (v_ErrorCode, v_ErrorMsg, v_Information);
? END;
? /
?

    
  相关解决方案