Skip to content

Instantly share code, notes, and snippets.

@wallyhall
Created August 10, 2020 11:10
Show Gist options
  • Save wallyhall/51cf26b2c7175c9b2cb68bd4ec78310e to your computer and use it in GitHub Desktop.
Save wallyhall/51cf26b2c7175c9b2cb68bd4ec78310e to your computer and use it in GitHub Desktop.
MySQL resignal and customised error message
DECLARE EXIT HANDLER FOR SQLEXCEPTION
BEGIN
DECLARE v_error_message VARCHAR(512);
DECLARE v_condition_number INT(1) UNSIGNED;
ROLLBACK;
GET DIAGNOSTICS v_condition_number = NUMBER;
GET DIAGNOSTICS CONDITION v_condition_number v_error_message = MESSAGE_TEXT;
SET v_error_message = CONCAT('Rolledback due to: "', v_error_message, '"');
RESIGNAL SET MESSAGE_TEXT = v_error_message;
END;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment