Exceptions: Difference between revisions

Content deleted Content added
Line 2,940:
SET result = numerator / denominator;
END IF;
END @
@
</lang>
The next example just raise an exception, does not wrap a raised one.
<lang sql pl>
BEGIN
SIGNAL SQLSTATE '75002'
SET MESSAGE_TEXT = 'Customer number is not known';
END @
@
</lang>
Output:
<pre>
$ db2 -td@ -tv exception.sql
db2 => BEGIN
...
DECLARE numerator INTEGER DEFAULT 12;
db2 (cont.) => END
DECLARE denominator INTEGER DEFAULT 0;
db2 (cont.) => @
DECLARE result INTEGER;
DECLARE overflow CONDITION for SQLSTATE '22003' ;
DECLARE CONTINUE HANDLER FOR overflow
RESIGNAL SQLSTATE '21543'
SET MESSAGE_TEXT = 'Zero division';
IF denominator = 0 THEN
SIGNAL overflow;
ELSE
SET result = numerator / denominator;
END IF;
END
DB21034E The command was processed as an SQL statement because it was not a
valid Command Line Processor command. During SQL processing it returned:
Line 2,971 ⟶ 2,963:
division". SQLSTATE=21543
 
db2 => BEGIN
db2 (cont.) => SIGNAL SQLSTATE '75001'
db2 (cont.) => SET MESSAGE_TEXT = 'Customer number is not known';
db2 (cont.) => END
END
db2 (cont.) => @
DB21034E The command was processed as an SQL statement because it was not a
valid Command Line Processor command. During SQL processing it returned: