MySQL:无法在触发器中使用SIGNAL [英] MySQL: Unable to use SIGNAL in Trigger

查看:1294
本文介绍了MySQL:无法在触发器中使用SIGNAL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用MySQL触发器生成错误消息。下面是我的代码:

I am trying to generate an error message using the MySQL trigger. Below is my code:

DELIMITER $$
CREATE TRIGGER `test_before_insert` BEFORE INSERT ON `Initial_Fees`
FOR EACH ROW
BEGIN
    IF ((SELECT Activation from Portfolio WHERE idPortfolio = New.idPortfolio)=false) THEN
        SIGNAL SQLSTATE '45000';
        SET MESSAGE_TEXT := 'Disabled Thing';
    END IF;
END$$   
DELIMITER ; 

但这总是会产生错误。我不知道错误是什么,因为它不是关于错误的任何东西,它只是错误。

But this always generates an error. I don't know what the error is, because It is not saying anything about the error, it is just "Error".

有任何建议吗?除此之外,有些人说使用 SIGNAL 会遇到问题,因为它可能是MySQL版本相关的。任何建议?

Any advice on this please? Apart from that, some people say using SIGNAL is subjected to issues because it can be MySQL version dependent. Any advice?

推荐答案

set message_text 语法 - 它们之间不应该有分号(; )。
此外,它使用 = 运算符,而不是:=

the set message_text clause is part of the signal syntax - there should not be a semicolon (;) between them. Additionally, it uses a = operator, not a :=:

DELIMITER $$
CREATE TRIGGER `test_before_insert` BEFORE INSERT ON `Initial_Fees`
FOR EACH ROW
BEGIN
    IF ((SELECT Activation from Portfolio WHERE idPortfolio = New.idPortfolio)=false) THEN
        SIGNAL SQLSTATE '45000' -- Note: no semicolon
        SET MESSAGE_TEXT = 'Disabled Thing'; -- Note the = operator
    END IF;
END$$   
DELIMITER ; 

这篇关于MySQL:无法在触发器中使用SIGNAL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆