Previous Topic: ExampleNext Topic: Example


RAISE ERROR Statement

The RAISE ERROR statement is used to signal an error or other condition in the manner of the SIGNAL statement. You must provide a valid SQLSTATE value when using the RAISE ERROR statement.

Note: SIGNAL, RAISE ERROR, and RESIGNAL statements that execute inside handlers do not activate additional condition handling. They instead cause the handler to be exited with the signaled condition and cause the execution of the compound statement that triggered the handler to abort. In addition, the compound statement that contains the handler definition is aborted if it is different from the compound statement that triggered the handler, the same as would happen if the handler failed to resolve the triggering condition. The SIGNAL, RAISE ERROR, and RESIGNAL statements should therefore be positioned as the last statements in your condition handler.

►►─ RAISE ERROR ─ (signal-value,error-message-text) ──────────────────────────►◄

Expansion of Where signal-value is defined as

├──┬─ condition-name ─┬────────────────────────────────────────────────────────┤
   └─ sqlstate-value ─┘

The RAISE ERROR statement functions identically to the following SIGNAL statement syntax:

Note: For more information on the SIGNAL statement, see SIGNAL Statement.

►►─ SIGNAL ─ signal-value ─ SET MESSAGE_TEXT = ─ error-message-text ──────────►◄

Expansion of Where signal-value is defined as

├──┬─ condition-name ─┬────────────────────────────────────────────────────────┤
   └─ sqlstate-value ─┘
signal-value

(Optional) When a signal-value is specified, existing Condition Areas within the current Diagnostics Area are pushed down in the Condition Area stack, that is, Condition Area number one becomes Condition Area number two. Condition Area number one is then populated with any supplied or implied RETURNED_SQLSTATE (supplied using sqlstate-value) and (or) CONDITION_IDENTIFIER (supplied using condition-name) in addition to any other information supplied in the SET signal-information clause. The statement-information-items are modified to indicate that a RESIGNAL statement was the last to modify the Diagnostics Area.

condition-name

See the condition-name information in the compound statement section that begins in Compound Statement.

sqlstate-value

See the sqlstate-value information in the compound statement section that begins in Compound Statement.

error-message-text

The text of an error message whose occurrence you want to signal an error.