//創建表的語句沒有問題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 ROWBEGINIF (LOCATE('://',NEW.`req_uri`)) THENSET 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”
2 回答

開心每一天1111
TA貢獻1836條經驗 獲得超13個贊
在 SET NEW.`domain` = SUBSTRING_INDEX(SUBSTRING_INDEX(NEW.`req_uri`,'/',3),'/',-2)
後面加上分號,END IF 後面也是

眼眸繁星
TA貢獻1873條經驗 獲得超9個贊
// 創建觸發器的語句報錯
應該先寫on 后寫 before insert吧
CREATE TRIGGER domain_Fill ON `web_record` BEFORE INSERT
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
添加回答
舉報
0/150
提交
取消