我想建一个触发器,当插入brxx表前,对插入的数据字段fbsj(data类型)进行处理,转化为“yy春”,通过newbing写出了下面的代码:
create trigger brxxfbjd
before insert on brxx
for each row
BEGIN
declare mm int;
set mm=month(new.fbsj);
case mm
WHEN mm=3 OR mm=4 OR mm=5 THEN SET NEW.fbjd = CONCAT(SUBSTR(NEW.fbsj, 1, 4), '春');
WHEN mm=6 OR mm=7 OR mm=8 THEN SET NEW.fbjd = CONCAT(SUBSTR(NEW.fbsj, 1, 4), '夏');
WHEN mm=9 OR mm=10 OR mm=11 THEN SET NEW.fbjd = CONCAT(SUBSTR(NEW.fbsj, 1, 4), '秋');
else SET NEW.fbjd = CONCAT(SUBSTR(NEW.fbsj, 1, 4), '冬');
END CASE;
END;
INSERT INTO brxx ( brmc, brxb, brqy, jbmc, fbsj )
VALUE
( 'xxx', '男', '浙江', '新冠', '2022-09-24' );
INSERT INTO brxx ( brmc, brxb, brqy, jbmc, fbsj )
VALUE
( 'xyz', '男', '浙江', '新冠', '2021-05-12' );
INSERT INTO brxx ( brmc, brxb, brqy, jbmc, fbsj )
VALUE
( 'wxy', '男', '浙江', '新冠', '2022-07-2' );
但是插入数据后fbjd全是冬
如图
这是为什么?这个触发器应该怎么改?