Because my answer to akf's comment is too long for a comment, I post it as a separate answer.
Here is why it doesn't achieve anything extra/useful.
Suppose we have the three tables mentioned by Peter:
SQL> create table mytable1 (mycolumn1) as select cast('JOHN' as varchar2(6)) from dual
2 /
Tabel is aangemaakt.
SQL> create table mytable2 (mycolumn2) as select cast('JOHN' as varchar2(6)) from dual
2 /
Tabel is aangemaakt.
SQL> create table mytable (loginid) as select cast('JOHN' as varchar2(6)) from dual
2 /
Tabel is aangemaakt.
And add a check constraint to make the third update statement fail:
SQL> alter table mytable add constraint no_jsmith_ck1 check (loginid <> 'JSMITH')
2 /
Tabel is gewijzigd.
The PL/SQL block can be as simple as this, and it fails:
SQL> begin
2 update mytable1
3 set mycolumn1 = 'JSMITH'
4 where mycolumn1 = 'JOHN'
5 ;
6 update mytable2
7 set mycolumn2 = 'JSMITH'
8 where mycolumn2 = 'JOHN'
9 ;
10 update mytable
11 set loginid = 'JSMITH'
12 where loginid = 'JOHN'
13 ;
14 commit
15 ;
16 end;
17 /
begin
*
FOUT in regel 1:
.ORA-02290: check constraint (RWK.NO_JSMITH_CK1) violated
ORA-06512: at line 10
And to show that everything was rollbacked, without issuing a rollback:
SQL> select * from mytable1
2 /
MYCOLU
------
JOHN
1 rij is geselecteerd.
SQL> select * from mytable2
2 /
MYCOLU
------
JOHN
1 rij is geselecteerd.
SQL> select * from mytable
2 /
LOGINI
------
JOHN
1 rij is geselecteerd.
So no exception handler is necessary here. Your proposed exception handler does this:
SQL> begin
2 update mytable1
3 set mycolumn1 = 'JSMITH'
4 where mycolumn1 = 'JOHN'
5 ;
6 update mytable2
7 set mycolumn2 = 'JSMITH'
8 where mycolumn2 = 'JOHN'
9 ;
10 update mytable
11 set loginid = 'JSMITH'
12 where loginid = 'JOHN'
13 ;
14 commit
15 ;
16 EXCEPTION
17 WHEN OTHERS THEN
18 ROLLBACK; --// Oracle will do this for you, but it doesnt hurt to be clear
19 DBMS_OUTPUT.put_line (DBMS_UTILITY.format_error_backtrace);
20 raise_application_error(-20001,'An error was encountered - '||SQLCODE||' -ERROR- '||SQLERRM);
21 END;
22 /
ORA-06512: at line 10
begin
*
FOUT in regel 1:
.ORA-20001: An error was encountered - -2290 -ERROR- ORA-02290: check constraint (RWK.NO_JSMITH_CK1) violated
ORA-06512: at line 20
Although it's not wrong, I see nothing of added value here.
SQL> select * from mytable1
2 /
MYCOLU
------
JOHN
1 rij is geselecteerd.
SQL> select * from mytable2
2 /
MYCOLU
------
JOHN
1 rij is geselecteerd.
SQL> select * from mytable
2 /
LOGINI
------
JOHN
1 rij is geselecteerd.
And why advice to add code that does nothing?
Regards,
Rob.