来自@Shaharsh Shah的代码:
DELIMITER $$
DROP TRIGGER /*!50032 IF EXISTS */ trig_auto_spid$$
CREATE
/*!50017 DEFINER = 'root'@'localhost' */
TRIGGER `trig_auto_spid` AFTER INSERT ON `tapes`
FOR EACH ROW BEGIN
SELECT REPLACE(TSpecID, 'TS', '') INTO @counter
FROM Tape_Specific_ID
ORDER BY TSpecID DESC LIMIT 1;
SET loopCnt = @counter + new.qty;
WHILE (@counter <= loopCnt) DO
INSERT INTO Tape_Specific_ID(TapesID, TSpecID)
VALUES (new.TapesID, CONCAT('TS', @counter));
SET @counter:=@counter + 1;
END WHILE;
END;
$$
DELIMITER ;
创建此触发器时发生错误错误1193(HY00):Uknown系统变量'loopCnt',为什么?有什么帮助吗?
答案 0 :(得分:2)
将其设为user variable
SET @loopCnt := @counter + new.qty;
WHILE (@counter <= @loopCnt) DO
更新1
SET @counter := 10;
SET @loopCnt := @counter + new.qty;
WHILE (@counter <= @loopCnt) DO
答案 1 :(得分:1)
尝试
SET @loopCnt = @counter + new.qty;
WHILE (@counter <= @loopCnt) DO
用户定义的变量需要前面有一个@
,否则它认为它是系统的一个变量,它没有定义。