DELIMITER $$
USE `t_girl`$$
DROP PROCEDURE IF EXISTS `sp_signal1`$$
CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_signal1`(
IN f_id INT
)
BEGIN
DECLARE con1 TINYINT DEFAULT 0;
DECLARE con1 CONDITION FOR SQLSTATE '23000';
DECLARE CONTINUE HANDLER FOR con1
BEGIN
SELECT 'Error Code : 22\r\nDuplicated!';
END;
INSERT INTO user_info VALUES (f_id);
END$$
DELIMITER ;
CALL sp_signal1(12);
query result
result
Error Code : 22
Duplicated!
用RESIGNAL/SIGNAL 重刷当前错误诊断区域。
DELIMITER $$
USE `t_girl`$$
DROP PROCEDURE IF EXISTS `sp_signal1`$$
CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_signal1`(
IN f_id INT
)
BEGIN
DECLARE con1 TINYINT DEFAULT 0;
DECLARE con1 CONDITION FOR SQLSTATE '23000';
DECLARE CONTINUE HANDLER FOR con1
BEGIN
resignal SET schema_name = 'action',
table_name = 'action_tb',
message_text = 'Duplicated!',
mysql_errno = 22;
/*
signal con1 SET schema_name = 'action',
table_name = 'action_tb',
message_text = 'Duplicated!',
mysql_errno = 22;
*/
END;
INSERT INTO user_info VALUES (f_id);
END$$
DELIMITER ;
CALL sp_signal1(12);
Query : call sp_signal1(12)
Error Code : 22
Duplicated!
Execution Time : 00:00:00:000
Transfer Time : 00:00:00:000
Total Time : 00:00:00:000