我创建了一个触发器:
DELIMITER $$
CREATE TRIGGER member_enrollment_update AFTER UPDATE ON memberships
FOR EACH ROW
BEGIN
INSERT INTO query_logs (QUERY,shop_id) VALUES ("update memberships set member_enrollment_status="+NEW.member_enrollment_status+" where card_no ='"+NEW.card_no+"'","LR00");
END $$
DELIMITER ;
其中列的数据类型为:
member_enrollment_status int(1) DEFAULT 0 ,
card_no varchar(15) NOT NULL
执行更新时,执行的SQL为:
update memberships set member_enrollment_status= 1 where card_no=3678000022 and member_enrollment_status = 0
警告是:
1292 - Truncated incorrect DOUBLE value: '''
1292 - Truncated incorrect DOUBLE value: ' where card_no =''
1292 - Truncated incorrect DOUBLE value: 'update memberships set member_enrollment_status='
In query_logs table, record is inserted but getting only the card_no (3678000022) as value of QUERY column.
请帮助解决错误
答案 0 :(得分:2)
我没有使用+
作为连接,而是使用INSERT INTO语句中的CONCAT
函数来解决问题。
INSERT INTO query_logs (QUERY,shop_id)
VALUES
(CONCAT("update memberships set member_enrollment_status=", NEW.member_enrollment_status,
"where card_no ='", NEW.card_no, "'"), "LR00");