为什么此mysql触发器给出错误?

时间:2019-01-21 11:55:50

标签: mysql oracle triggers

我正在尝试将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对我来说很新。

1 个答案:

答案 0 :(得分:4)

尝试纠正线路信令:

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