REM error.sql
REM Version 1.0, last updated 6/3/97
REM This block demonstrates using an exception section to record errors,
REM as described in Chapter 1 of _Oracle8 PL/SQL Programming_ by Scott Urman.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;
/
没有什么别的了
REM Version 1.0, last updated 6/3/97
REM This block demonstrates using an exception section to record errors,
REM as described in Chapter 1 of _Oracle8 PL/SQL Programming_ by Scott Urman.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;
/
没有什么别的了
error_text有这些东西吗、???
就够了啊,我觉得够用了.还可以自己定义抛出异常,然后自己捕捉异常显示的信息.
out_of_balance EXCEPTION;
BEGIN
...
BEGIN ---------- sub-block begins
...
IF ... THEN
RAISE out_of_balance; -- raise the exception
END IF;
EXCEPTION
WHEN out_of_balance THEN
-- handle the error
RAISE; -- reraise the current exception
END; ------------ sub-block ends
EXCEPTION
WHEN out_of_balance THEN
-- handle the error differently
...
END;
Omitting the exception name in a RAISE statement--allowed only in an exception handler--reraises the current exception.以上例子,说明当并列成立异常,oracle只执行一个例外,不会往下执行,还有好多例子,楼主细心研究,会发出现意思不到事情.