This shows you the differences between two versions of the page.
— |
signal [2015/09/23 20:27] (current) |
||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== SIGNAL Statement - PL/HQL Reference====== | ||
+ | SIGNAL statement raises a user-defined condition (exception). | ||
+ | |||
+ | **Syntax**: | ||
+ | |||
+ | <code language="sql"> | ||
+ | SIGNAL condition_name; | ||
+ | </code> | ||
+ | |||
+ | **Example:** | ||
+ | |||
+ | Raise a condition if the number of rows is not equal to the specified number: | ||
+ | |||
+ | <code language="sql"> | ||
+ | DECLARE cnt INT DEFAULT 0; | ||
+ | DECLARE wrong_cnt_condition CONDITION; | ||
+ | |||
+ | DECLARE EXIT HANDLER FOR wrong_cnt_condition | ||
+ | PRINT 'Wrong number of rows'; | ||
+ | |||
+ | SELECT COUNT(*) INTO cnt FROM TABLE (VALUES (1,2)); | ||
+ | |||
+ | IF cnt <> 1 THEN | ||
+ | SIGNAL wrong_cnt_condition; | ||
+ | END IF; | ||
+ | </code> | ||
+ | |||
+ | **Compatibility**: IBM DB2, Teradata and MySQL | ||
+ | |||
+ | **Version**: PL/HQL 0.3.1 | ||
+ | |||
+ | **See also:** | ||
+ | * [[error-handling|Error Handling]] | ||
+ | * [[declare-condition|DECLARE CONDITION]] | ||
+ | * [[declare-handler|DECLARE HANDLER]] | ||
+ | * [[sqlcode|SQLCODE]] | ||
+ | * [[sqlstate|SQLSTATE]] | ||
+ | * [[get-diagnostics|GET DIAGNOSTICS]] | ||
+ | * [[resignal|RESIGNAL]] |