RAISE_ERROR

Click to skip syntax diagram
Read syntax diagramSkip visual syntax diagram>>-RAISE_ERROR--(--sqlstate--,--diagnostic-string--)-----------><
 

The RAISE_ERROR function causes the statement that invokes the function to return an error with the specified SQLSTATE (along with SQLCODE -438) and error condition. The RAISE_ERROR function always returns NULL with an undefined data type.

sqlstate
An expression that returns a character or Unicode graphic string constant with exactly 5 characters that follow the rules for SQLSTATEs:

If the SQLSTATE does not conform to these rules, an error is returned.

diagnostic-string
Specifies a string that describes the error or warning.

If an SQLCA is used,

Since the data type of the result of RAISE_ERROR is undefined, it may only be used where parameter markers are allowed. To use this function in a context where parameter markers are not allowed (such as alone in a select list), you must use a cast specification to give a data type to the null value that is returned. The RAISE_ERROR function cannot be used with CASE expressions.

Example