ALLBASE/SQL Reference Manual (36216-90216)

Chapter 11 475
SQL Statements E - R
RAISE ERROR
Parameters and local variables are only used within procedures. Host
variables are only used within embedded SQL. Dynamic parameters are
only used within dynamic SQL.
Description
RAISE ERROR is for user-defined errors. The errors returned are application specific.
•If
ErrorNumber
or
ErrorText
is NULL, an error is returned and the message is not
generated.
ErrorNumber
, if specified, must be greater than 0.
Execution of RAISE ERROR causes the number of the raised error to be placed in sqlcode
and the RAISE ERROR text to be placed in the message buffer.
Since an error condition is the expected result of the statement, no corrective action
need be taken except as directed by the application developer. Applications can use
SQLEXPLAIN to fetch the text of the message and interpret it appropriately. Applications
can also examine and/or display sqlcode.
You can use the DESCRIBE INPUT statement on this statement after you PREPARE it to
show the number and characteristics of dynamic parameters, if any are used.
Authorization
Any user can issue this statement.
Examples
1. Example coded in a procedure to be invoked by a rule
SELECT COUNT(*) INTO :rows FROM PurchDB.Orders
WHERE VendorNumber = :VendorNumber;
IF :rows <> 0 THEN
RAISE ERROR 1 MESSAGE 'Vendor number exists in the "Orders" table.';
ENDIF;
2. Interactive example
isql=> raise error 1 message 'This is error 1';
This is error 1
isql=>
3. Example using dynamic parameters
EXEC SQL PREPARE MyCmd from 'RAISE ERROR ? MESSAGE ?';
Accept values for error number and message text into host variables :ErrorNumber and
:ErrorText, then execute the prepared command:
EXEC SQL EXECUTE MyCmd USING :ErrorNumber, :ErrorText;