MySQL:无法在触发器中使用信号

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

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Execute complex raw SQL query in EF6(在EF6中执行复杂的原始SQL查询)
Hibernate reactive No Vert.x context active in aws rds(AWS RDS中的休眠反应性非Vert.x上下文处于活动状态)
Bulk insert with mysql2 and NodeJs throws 500(使用mysql2和NodeJS的大容量插入抛出500)
Flask + PyMySQL giving error no attribute #39;settimeout#39;(FlASK+PyMySQL给出错误,没有属性#39;setTimeout#39;)
auto_increment column for a group of rows?(一组行的AUTO_INCREMENT列?)
Sort by ID DESC(按ID代码排序)