读书人

pl sql中如何避免错误

发布时间: 2012-12-26 14:39:29 作者: rapoo

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;
? /
?

    

读书人网 >SQL Server

热点推荐