MySQL: Unable to use SIGNAL in Trigger(MySQL:无法在触发器中使用信号)
问题描述
我正在尝试使用 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:无法在触发器中使用信号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:MySQL:无法在触发器中使用信号


基础教程推荐
- MySQL 5.7参照时间戳生成日期列 2022-01-01
- 带有WHERE子句的LAG()函数 2022-01-01
- while 在触发器内循环以遍历 sql 中表的所有列 2022-01-01
- ORA-01830:日期格式图片在转换整个输入字符串之前结束/选择日期查询的总和 2021-01-01
- 从字符串 TSQL 中获取数字 2021-01-01
- 使用 VBS 和注册表来确定安装了哪个版本和 32 位 2021-01-01
- 带更新的 sqlite CTE 2022-01-01
- CHECKSUM 和 CHECKSUM_AGG:算法是什么? 2021-01-01
- 如何在 CakePHP 3 中实现 INSERT ON DUPLICATE KEY UPDATE aka upsert? 2021-01-01
- MySQL根据从其他列分组的值,对两列之间的值进行求和 2022-01-01