这是我尝试用来创建触发器的代码:
-- Dumping structure for trigger kavanga_lead.click_links_insert
DROP TRIGGER IF EXISTS `click_links_insert`;
SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='';
DELIMITER //
CREATE TRIGGER `click_links_insert` AFTER INSERT ON `click_links` FOR EACH ROW BEGIN
INSERT INTO actions_log
(
`uid`,
`table`,
`action`,
`new`
)
VALUES
(
@user_id,
'click_links',
'insert',
concat(NEW.id ,'|', NEW.`contents`, '|', NEW.channel_id, '|', NEW.name, '|', NEW.hidden, '|', if(NEW.prefix_id is null,'',NEW.prefix_id) '|', if(NEW.postfix_id is null,'',NEW.postfix_id))
);
END//
DELIMITER ;
SET SQL_MODE=@OLD_SQL_MODE;
我一直收到错误(1583)Incorrect parameters in the call to concat
。
如果我不使用if(NEW.prefix_id is null,'',NEW.prefix_id)
而只使用NEW.prefix_id
,则效果很好。但是此字段可以是null
,因此所有concat
的结果都会变为null
。
所以,问题是我如何在IF
电话中使用CONCAT
身份?
答案 0 :(得分:3)
那是因为您在comma
尝试后忘了一个if(NEW.prefix_id is null,'',NEW.prefix_id)
:
concat(NEW.id ,'|', NEW.`contents`, '|', NEW.channel_id, '|', NEW.name, '|', NEW.hidden, '|', if(NEW.prefix_id is null,'',NEW.prefix_id), '|', if(NEW.postfix_id is null,'',NEW.postfix_id))
答案 1 :(得分:2)
答案 2 :(得分:0)
由于comma
语句后缺少inline IF
,您的查询无效。
concat(NEW.id ,'|', NEW.`contents`, '|',
NEW.channel_id, '|', NEW.name, '|', NEW.hidden, '|',
if(NEW.prefix_id is null,'',NEW.prefix_id) '|',
-- ^ error here
if(NEW.postfix_id is null,'',NEW.postfix_id))
一定是
concat(NEW.id ,'|', NEW.`contents`, '|',
NEW.channel_id, '|', NEW.name, '|', NEW.hidden, '|',
if(NEW.prefix_id is null,'',NEW.prefix_id), '|',
if(NEW.postfix_id is null,'',NEW.postfix_id))