问题描述
我的代码是:我正在使用mysql 5.6和workbench 6.3CE
My code is:i am using mysql 5.6 and workbench 6.3CE
CREATE DEFINER=`root`@`windows7test-pc` PROCEDURE `p`(divisor INT)
BEGIN
Declare MESSAGE_TEXT varchar(200);
IF divisor = 0 THEN
BEGIN
DECLARE my_error CONDITION FOR SQLSTATE '45000';
SIGNAL my_error;
set MESSAGE_TEXT='error occured in if block';
END;
END IF;
END
当我应用此存储过程时,我没有收到任何错误,但是当我通过调用 call p(0)语句运行此存储库时,我仅收到系统错误消息,该错误消息为错误代码:1644 未处理的用户定义的异常情况.但是我的问题是,为什么mysql服务器未生成我的错误消息,是 MESSAGE_TEXT ='if块中发生了错误'; ?
when i apply this stored procedure then i get no error but when i run this by calling call p(0) statement then i get only system error message which is Error Code: 1644 Unhandled user-defined exception condition.but my question is that why the mysql server not generate my error message whic is MESSAGE_TEXT='error occured in if block'; ?
推荐答案
您没有将message_text
声明为变量.
You do not declare message_text
as a variable.
您不DECLARE ... CONDITION
.
您必须在与SIGNAL
相同的语句中包含SET
的值.
You do have to include the values to SET
in the same statement as SIGNAL
.
语法很简单:
IF divisor = 0 THEN
SIGNAL SQLSTATE '45000' SET message_text = 'division: ur doing it wrong';
END IF;
这篇关于系统变量"MESSAGE_TEXT"在MySQL中不能使用SIGNAL语句?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!