SIGNAL
Remarks
The SIGNAL statement allows you to signal an exception condition or a completion condition other than successful completion.
Signalling a SQLSTATE value causes SQLSTATE to be set to a specific value. This value is then returned to the user, or made available to the calling procedure (through the SQLSTATE value). This value is available to the application calling the procedure.
You can also specify an error message with the SQLSTATE value.
Note SIGNAL is available only inside a stored procedure or user-defined function.
Syntax
SIGNAL SQLSTATE_value [, error_message ]
SQLSTATE_value ::= user-defined value
error_message ::= user-defined message
Examples
The following example prints the initial SQLSTATE value 00000, then prints “SQLSTATE exception found” after the signal is raised. The final SQLSTATE value printed is W9001.
CREATE PROCEDURE GenerateSignal();
BEGIN
SIGNAL 'W9001';
END;
CREATE PROCEDURE TestSignal() WITH DEFAULT HANDLER;
BEGIN
PRINT SQLSTATE;
CALL GenerateSignal();
IF SQLSTATE <> '00000' THEN
PRINT 'SQLSTATE exception found';
END IF;
PRINT SQLSTATE;
END;
============
CREATE PROCEDURE GenerateSignalWithErrorMsg();
BEGIN
SIGNAL 'W9001', 'Invalid Syntax';
END;
CALL GenerateSignalWithErrorMsg()
See Also