创建表没有问题,创建触发器总是提示“end if end ”处有错误?为什么

//创建表的语句没有问题
CREATE TABLE `web_record` (
`timestamp` decimal(15,3) DEFAULT NULL,
`resp_time` int(11) DEFAULT NULL,
`src_ip` char(15) DEFAULT NULL,
`cache_status` varchar(20) DEFAULT NULL,
`http_status` varchar(10) DEFAULT NULL,
`reply_size` int(11) DEFAULT NULL,
`req_method` varchar(20) DEFAULT NULL,
`req_uri` varchar(1000) DEFAULT NULL,
`username` varchar(20) DEFAULT NULL,
`peer_access` varchar(20) DEFAULT NULL,
`dst_ip` char(15) DEFAULT NULL,
`mime_type` varchar(50) DEFAULT NULL,
`domain` varchar(200) DEFAULT NULL,
`id` bigint(20) NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`id`),
KEY `id` (`id`)
)

// 创建触发器的语句报错
CREATE TRIGGER domain_Fill BEFORE INSERT ON `web_record`
FOR EACH ROW
BEGIN
IF (LOCATE('://',NEW.`req_uri`)) THEN
SET NEW.`domain` = SUBSTRING_INDEX(SUBSTRING_INDEX(NEW.`req_uri`,'/',3),'/',-2)
END IF 
END

创建表没有问题,创建触发器总是提示“#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'END IF END' at line 6

Helenr
浏览 93回答 2
2回答

开心每一天1111

在 SET NEW.`domain` = SUBSTRING_INDEX(SUBSTRING_INDEX(NEW.`req_uri`,'/',3),'/',-2)後面加上分号,END IF 後面也是

眼眸繁星

// 创建触发器的语句报错应该先写on 后写 before insert吧CREATE TRIGGER domain_Fill ON `web_record` BEFORE INSERT FOR EACH ROWBEGINIF (LOCATE('://',NEW.`req_uri`)) THENSET NEW.`domain` = SUBSTRING_INDEX(SUBSTRING_INDEX(NEW.`req_uri`,'/',3),'/',-2)END IF END
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

MySQL