【 使用环境 】生产环境 or 测试环境 测试环境
【 OB or 其他组件 】OceabBase_CE 4.2.1.2
【 使用版本 】OceabBase_CE 4.2.1.2
【问题描述】清晰明确描述问题
创建触发器之后,无法正常插入数据。同样创建触发器的sql和插入数据的sql放到navicate上,可以正常插入数据,且数据正确。
创建触发器的sql:
DELIMITER //
CREATE TRIGGER update_serial_id
BEFORE INSERT ON TAccountCashInOut
FOR EACH ROW
BEGIN
DECLARE max_serial_id INT;
IF NEW.FSerialId = 0 THEN
SELECT MAX(FSerialId) INTO max_serial_id FROM TAccountCashInOut;
SET NEW.FSerialId = IFNULL(max_serial_id, 0) + 1;
END IF;
END;
//
DELIMITER ;
插入数据的sql:
Insert Into TAccountCashInOut(FSerialId, FDate, FAccountNo) ValueS(0, “2024-04-16”, “ln”);
报错 ErrorCode = 1442, SQLState = HY000, Details = Can’t update table ‘TAccountCashInOut’ in stroed function/trigger because it is already used by statement which invoked this function/trigger
失败原因:
ErrorCode = 1442, SQLState = HY000, Details = Can’t update table ‘TAccountCashInOut’ in stored function/trigger because it is already used by statement which invoked this stored function/trigger.