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:无法在触发器中使用信号


基础教程推荐
- 在多列上分布任意行 2021-01-01
- 在 MySQL 中:如何将表名作为存储过程和/或函数参数传递? 2021-01-01
- 如何根据该 XML 中的值更新 SQL 中的 XML 2021-01-01
- oracle区分大小写的原因? 2021-01-01
- 什么是 orradiag_<user>文件夹? 2022-01-01
- 如何在 SQL 中将 Float 转换为 Varchar 2021-01-01
- mysql选择动态行值作为列名,另一列作为值 2021-01-01
- MySQL 中的类型:BigInt(20) 与 Int(20) 2021-01-01
- 表 './mysql/proc' 被标记为崩溃,应该修复 2022-01-01
- 二进制文件到 SQL 数据库 Apache Camel 2021-01-01