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.1 中的抽象触发器来更新审计日志 2021-01-01
- SQL 效率:WHERE IN 子查询 vs. JOIN 然后 GROUP 2021-01-01
- 如何使用 mysql.connector 禁用查询缓存 2022-01-01
- SQL Server 实例在登录协商期间返回无效或不受支持的协议版本 2021-01-01
- 是否可以执行按位分组功能? 2021-01-01
- SSMS 中的权限问题:“对象 'extended_properties'、数据库 'mssqlsystem_resource'、... 错误 229)上的 SELECT 权限被拒绝" 2022-01-01
- 将 SQL Server DateTime 列迁移到 DateTimeOffset 2021-01-01
- 在 SQL 中连接多个表 2021-01-01
- SQL:使用来自具有相同列名的两个表中的数据... 2021-01-01
- 无法解决整理冲突 2021-01-01
