Syntax:
SIGNAL condition_value
    [SET signal_information_item
    [, signal_information_item] ...]

condition_value:
    SQLSTATE [VALUE] sqlstate_value
  | condition_name

signal_information_item:
    condition_information_item_name = simple_value_specification

condition_information_item_name:
    CLASS_ORIGIN
  | SUBCLASS_ORIGIN
  | MESSAGE_TEXT
  | MYSQL_ERRNO
  | CONSTRAINT_CATALOG
  | CONSTRAINT_SCHEMA
  | CONSTRAINT_NAME
  | CATALOG_NAME
  | SCHEMA_NAME
  | TABLE_NAME
  | COLUMN_NAME
  | CURSOR_NAME

condition_name, simple_value_specification:
    (see following discussion)

SIGNAL is the way to "return" an error. SIGNAL provides error
information to a handler, to an outer portion of the application, or to
the client. Also, it provides control over the error's characteristics
(error number, SQLSTATE value, message). Without SIGNAL, it is
necessary to resort to workarounds such as deliberately referring to a
nonexistent table to cause a routine to return an error.

No special privileges are required to execute the SIGNAL statement.

The condition_value in a SIGNAL statement indicates the error value to
be returned. It can be an SQLSTATE value (a 5-character string literal)
or a condition_name that refers to a named condition previously defined
with DECLARE ... CONDITION (see [HELP DECLARE CONDITION]).

An SQLSTATE value can indicate errors, warnings, or "not found." The
first two characters of the value indicate its error class, as
discussed in
https://mariadb.com/kb/en/signal/#signal-condition-inf
ormation-items. Some signal values cause statement termination; see
https://mariadb.com/kb/en/signal/#signal-effects.

The SQLSTATE value for a SIGNAL statement should not start with '00'
because such values indicate success and are not valid for signaling an
error. This is true whether the SQLSTATE value is specified directly in
the SIGNAL statement or in a named condition referred to in the
statement. If the value is invalid, a Bad SQLSTATE error occurs.

To signal a generic SQLSTATE value, use '45000', which means "unhandled
user-defined exception."

The SIGNAL statement optionally includes a SET clause that contains
multiple signal items, in a comma-separated list of
condition_information_item_name = simple_value_specification
assignments.

Each condition_information_item_name may be specified only once in the
SET clause. Otherwise, a Duplicate condition information item error
occurs.

Valid simple_value_specification designators can be specified using
stored procedure or function parameters, stored program local variables
declared with DECLARE, user-defined variables, system variables, or
literals. A character literal may include a _charset introducer.

For information about permissible condition_information_item_name
values, see
https://mariadb.com/kb/en/signal/#signal-condition-inf
ormation-items.

URL: https://mariadb.com/kb/en/signal/

