gpt4 book ai didi

mysql - 为什么这个mysql触发器报错?

转载 作者:行者123 更新时间:2023-11-29 04:33:00 25 4
gpt4 key购买 nike

我正在尝试将我的 oracle 触发器转换为 mysql,但出现错误。这是我的 mysql 触发器:

delimiter //
CREATE TRIGGER z_asdsdas BEFORE UPDATE ON PRODUCT
FOR EACH ROW
BEGIN
DECLARE v_result INT;
SET v_result = 0;
IF 'BETWEEN' = 'BETWEEN' THEN
IF NEW.PRIJS >= 1 AND NEW.PRIJS <= 10 THEN
SET v_result = 1;
END IF;
ELSE
IF NEW.PRIJS < 1 OR NEW.PRIJS > 10 THEN
SET v_result = 1;
END IF;
END IF;

IF v_result = 0 THEN
signal sqlstate -20000 set msgtext = 'error here...';
END IF;
END //

DELIMITER ;

我首先给了 mysql 触发器静态值来测试它是否应该工作。这是我的 oracle 触发器:

CREATE OR REPLACE TRIGGER BRG_<code>_<attribute_table>_TRG
BEFORE DELETE OR INSERT OR UPDATE
ON <attribute_table>
FOR EACH ROW
DECLARE
L_OPER VARCHAR2(3);
L_ERROR_STACK VARCHAR2(4000);
BEGIN
IF INSERTING
THEN
L_OPER := 'INS';
ELSIF UPDATING
THEN
L_OPER := 'UPD';
END IF;
DECLARE
L_PASSED BOOLEAN := TRUE;
BEGIN
IF L_OPER IN ('INS', 'UPD')
THEN
IF '<operator>' = 'BETWEEN' THEN
L_PASSED := :NEW.<attribute_column> <GreaterOrEqual> <range_min> AND :NEW.<attribute_column> <LessOrEqual> <range_max>;
ELSE
L_PASSED := :NEW.<attribute_column> <LessThen> <range_min> OR :NEW.<attribute_column> <GreaterThen> <range_max>;
END IF;

IF NOT L_PASSED
THEN
raise_application_error(-20000, '<error>');
END IF;
END IF;
END;
END;

编译器在 if 语句处给出红线,并在第 17 行给出一条消息:语法错误。知道我做错了什么吗? Mysql 对我来说很新。

最佳答案

尝试更正线路信号:

...
SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'error here...';
...

关于mysql - 为什么这个mysql触发器报错?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54289465/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com