Monday, March 2, 2009

Exception Handling

--+----------------------------------------------------
--| Declaration section
--+----------------------------------------------------
Declare
v_SqlCode Number ; --code for the error
v_SqlErrM Varchar2(200); --message text for the error
v_User Varchar2(8) ; --current database user
v_Info Varchar2(100); --info about the error
--+----------------------------------------------------
--| Execution section - create an error
--+----------------------------------------------------
Begin
Update Students
Set Current_Credits = 'A';
--+----------------------------------------------------
--| Exception Handling section. Assign values to the
--| log variables, using built-in functions.
--+----------------------------------------------------
Exception
When Others Then
v_SqlCode := SqlCode;
v_SqlErrM := SqlErrM;
v_User := User;
v_Info := 'Date:' || To_Char(Sysdate) ||
' User:' || v_User;
--+--------------------------------------
--| Insert the log message into log_table
--+--------------------------------------
Insert Into Log_Table(Code ,Message ,Info )
Values(v_SqlCode,v_SqlErrM ,v_Info);
End;
/

No comments:

Post a Comment