Exception handling using update [message #422359] |
Tue, 15 September 2009 16:15  |
prachij593
Messages: 266 Registered: May 2009
|
Senior Member |
|
|
Can we do something like this in exception handling?
when errors occurs then update the counter to -1 in error table.
CREATE OR REPLACE PROCEDURE T(in_emp_id number
) IS
o_return_cdenbr;
BEGIN
INS_EMP_DATA(in_emp_id,o_return_cde);
EXCEPTION
WHEN OTHERS THEN
UPDATE ERROR_T SET CNTR=-1 WHERE ID=IN_ID;
END;
Thanks
|
|
|
|
|
|
|
Re: Exception handling using update [message #422376 is a reply to message #422359] |
Tue, 15 September 2009 23:50   |
ayush_anand
Messages: 417 Registered: November 2008
|
Senior Member |
|
|
Quote:o_return_cdenbr;
what is this??
SQL>
SQL> create table test
2 (
3 ctr number
4 );
Table created.
SQL> insert into test values (1);
1 row created.
SQL> commit;
Commit complete.
ed
Wrote file afiedt.buf
1 CREATE OR REPLACE PROCEDURE test_p_del(in_emp_id number
2 ) IS
3 BEGIN
4 RAISE NO_DATA_FOUND;
5 EXCEPTION
6 WHEN OTHERS THEN
7 UPDATE TEST SET CTR=-1;
8* END;
SQL> /
Procedure created.
SQL> begin
2 test_p_del(1);
3 end;
4 /
PL/SQL procedure successfully completed.
SQL> select * from test;
CTR
----------
-1
This works 
But you must have some exception handling mechanism.Otherwise bad design can lead to costly workarounds in future.
[Updated on: Tue, 15 September 2009 23:52] Report message to a moderator
|
|
|
|
|
|
|
|
|
|
Re: Exception handling using update [message #422403 is a reply to message #422359] |
Wed, 16 September 2009 02:34   |
JRowbottom
Messages: 5933 Registered: June 2006 Location: Sunny North Yorkshire, ho...
|
Senior Member |
|
|
I think Michel's point needs to be re-emphasised.Quote:When you use WHEN OTHERS without RAISE you can be sure you are wrong in 99.999% of the cases.
When Others catches any exception - including many for which you just want to let the exception pass back to the calling program.
You should put your update code in an exception handler that only catches the exceptions that you EXPECT to be raised by the procedure you call.
|
|
|
|
Re: Exception handling using update [message #422445 is a reply to message #422443] |
Wed, 16 September 2009 08:59   |
 |
Michel Cadot
Messages: 68733 Registered: March 2007 Location: Saint-Maur, France, https...
|
Senior Member Account Moderator |
|
|
prachij593 wrote on Wed, 16 September 2009 15:45Sir, requirement is when any error occurs update the table ERROR_T.
Thanks
This requirement is stup... meaningless.
If the error is "database crashed" or "your session has been killed" or "unable to allocate memory", how could you update the table?
Regards
Michel
[Updated on: Wed, 16 September 2009 09:00] Report message to a moderator
|
|
|
Re: Exception handling using update [message #422446 is a reply to message #422443] |
Wed, 16 September 2009 09:17   |
JRowbottom
Messages: 5933 Registered: June 2006 Location: Sunny North Yorkshire, ho...
|
Senior Member |
|
|
Any error?
So if you've got an error caused by the tablespace being full, or an ORA-000257 Archiver error, then you think that setting this value to -1 and ignoring the error is a good idea?
|
|
|
|
Re: Exception handling using update [message #422460 is a reply to message #422446] |
Wed, 16 September 2009 12:01   |
prachij593
Messages: 266 Registered: May 2009
|
Senior Member |
|
|
'You should put your update code in an exception handler that only catches the exceptions that you EXPECT to be raised by the procedure you call.'
Requirement is call two procedure from the main say X and Y and if there is any error during the transaction then update the column by +1 for each record (say based on emp id)
|
|
|
|