Anonymous block with error handling
SQL> --Anonymous block with error handling:
SQL>
SQL> DECLARE
2 x NUMBER;
3 BEGIN
4 x := 10/0; -- this will cause a predefined exception
5 y := x + 1; -- this line will never run
6 EXCEPTION
7
8 WHEN ZERO_DIVIDE THEN -- this is the handler
9 X := 0;
10 END;
11
12
13 /
y := x + 1; -- this line will never run
*
ERROR at line 5:
ORA-06550: line 5, column 3:
PLS-00321: expression 'OGC_Y' is inappropriate as the left hand side of an assignment statement
ORA-06550: line 5, column 3:
PL/SQL: Statement ignored
SQL>
Related examples in the same category