Condition Handling Valid  condition_number  designators can be 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. A warning occurs if the condition number is not in the range from 1 to the number of condition areas that have information. In this case, the warning is added to the diagnostics area without clearing it. When a condition occurs, MySQL does not populate all condition items recognized by  GET DIAGNOSTICS . For example: In standard SQL, if there are multiple conditions, the first condition relates to the  SQLSTATE  value returned for the previous SQL statement. In MySQL, this is not guaranteed. To get the main error, you cannot do this: Instead, retrieve the condition count first, then use it to specify which condition number to inspect: For information about permissible statement and condition information items, and which ones are populated when a condition occurs, see Diagnostics Area Information Items. Here is an example that uses  GET DIAGNOSTICS  and an exception handler in stored procedure context to assess the outcome of an insert operation. If the insert was successful, the procedure uses  GET DIAGNOSTICS  to get the rows-affected count. This shows that you can use  GET DIAGNOSTICS  multiple times to retrieve information about a statement as long as the current diagnostics area has not been cleared. 2813 CREATE PROCEDURE do_insert(value INT) BEGIN -- Declare variables to hold diagnostics area information DECLARE code CHAR(5) DEFAULT ’00000’; DECLARE msg TEXT; DECLARE nrows INT; DECLARE result TEXT; -- Declare exception handler for failed insert DECLARE CONTINUE HANDLER FOR SQLEXCEPTION BEGIN GET DIAGNOSTICS CONDITION 1 code = RETURNED_SQLSTATE, msg = MESSAGE_TEXT; END; -- Perform the insert INSERT INTO t1 (int_col) VALUES(value); -- Check whether the insert was successful IF code = ’00000’ THEN GET DIAGNOSTICS nrows = ROW_COUNT; SET result = CONCAT(’insert succeeded, row count = ’,nrows); ELSE SET result = CONCAT(’insert failed, error = ’,code,’, message = ’,msg); END IF; -- Say what happened SELECT result; GET DIAGNOSTICS @cno = NUMBER; GET DIAGNOSTICS CONDITION @cno @errno = MYSQL_ERRNO; GET DIAGNOSTICS CONDITION 1 @errno = MYSQL_ERRNO; mysql>  GET DIAGNOSTICS CONDITION 1 @p5 = SCHEMA_NAME, @p6 = TABLE_NAME; mysql>  SELECT @p5, @p6; +------+------+ | @p5 | @p6 | +------+------+ | | | +------+------+