mariadb Maria DB -在插入触发器之前将值分配给NEW.field

lnlaulya  于 2022-11-08  发布在  其他
关注(0)|答案(1)|浏览(88)

我是新的,背景是完全基于甲骨文和相关产品。我已经安装了XAMPP 3. 3. 0,我已经创建了一个触发器,工作正常。

DELIMITER $$

CREATE OR REPLACE 
    TRIGGER bi_cancel_booking BEFORE INSERT
    ON cancelled_booking
    FOR EACH ROW BEGIN
    --
    DECLARE next_receipt VARCHAR(20);
    DECLARE rct_no INT(5);
    --
    SELECT MAX(starting_number)+1, CONCAT(receipt_prefix,'-',MAX(starting_number)+1)
      INTO rct_no, next_receipt 
      FROM com_receipt_types
     WHERE receipt_type = 'Cancel Booking';

    END$$

DELIMITER ;

但在使用NEW.cancel_receipt_no(参见以下代码)时,它显示错误:错误代码:1327未宣告的变数:新产品

DELIMITER $$

CREATE OR REPLACE 
    TRIGGER bi_cancel_booking BEFORE INSERT
    ON cancelled_booking
    FOR EACH ROW BEGIN
    --
    DECLARE next_receipt VARCHAR(20);
    DECLARE rct_no INT(5);
    --
    SELECT MAX(starting_number)+1, CONCAT(receipt_prefix,'-',MAX(starting_number)+1)
      INTO rct_no, NEW.cancel_receipt_no
      FROM com_receipt_types
     WHERE receipt_type = 'Cancel Booking';

    END$$

DELIMITER ;

是否有任何限制,使我不能像在这里的第一个代码中那样将值赋给NEW.field,当我尝试将值赋为:新的。取消_收据_编号:=下一个_收据,然后它也显示错误。请帮助,我怎么可以在这里做这个?

13z8s7eq

13z8s7eq1#

我使用了以下代码,错误已消失(使用了SET):

SET NEW.取消收货编号=下一个收货;

DELIMITER $$

CREATE OR REPLACE 
TRIGGER bi_cancel_booking BEFORE INSERT
ON cancelled_booking
FOR EACH ROW BEGIN
--
DECLARE next_receipt VARCHAR(20);
DECLARE rct_no INT(5);
--
SELECT MAX(starting_number)+1, CONCAT(receipt_prefix,'-',MAX(starting_number)+1)
  INTO rct_no, next_receipt 
  FROM com_receipt_types
 WHERE receipt_type = 'Cancel Booking';

    SET NEW.cancel_receipt_no := next_receipt;

    END$$

DELIMITER ;

因为我的知识太少了,慢慢的,我会在各位前辈的帮助下学会这些东西。

相关问题