我收到以下错误,我不知道原因:
1064 - 您的SQL语法出错;检查与MySQL服务器版本对应的手册,以获得正确的语法 靠近';
DELIMITER $$
CREATE PROCEDURE staffnewid_all()
BEGIN
DECLARE x int;
DECLARE y int;
DECLARE z int;
DECLARE charid varchar;
DECLARE a int;
DECLARE b int;
DROP TEMPORARY TABLE IF EXISTS cms_psm.temp_nostaf;
CREATE TEMPORARY TABLE IF NOT EXISTS cms_psm.temp_nostaf (tempid INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY, char_id varchar(1));
INSERT INTO cms_psm.temp_nostaf (char_id) SELECT DISTINCT(LEFT(nostaf, 1)) FROM staf_new_no;
SET a = (SELECT min(tempid) FROM cms_psm.temp_nostaf ORDER BY tempid);
SET b = (SELECT COUNT(tempid) FROM cms_psm.temp_nostaf);
WHILE a<=b DO
SET charid = (SELECT char_id FROM cms_psm.temp_nostaf WHERE tempid=a);
SET x = (SELECT count(*) FROM staf_peribadi WHERE nostaf LIKE CONCAT('%', charid, '%') ORDER BY nostaf ASC);
SET y = (SELECT min(id) FROM staf_new_no WHERE nostaf LIKE CONCAT('%', charid, '%') ORDER BY nostaf ASC);
SET z = 1;
WHILE z<=x DO
UPDATE staf_new_no SET nostaf_new = CONCAT(charid, LPAD(z, 6, '0')) WHERE id=y;
SET z = z + 1 ;
SET y = y + 1 ;
END WHILE;
SET a = a + 1 ;
END WHILE;
END
答案 0 :(得分:0)
使用语句
结束您的代码END;$$
Delimiter ;
它有效
答案 1 :(得分:0)
DECLARE charid varchar;
应该是
DECLARE charid varchar(1);
感谢您的帮助
答案 2 :(得分:0)
BEGIN
DECLARE x int;
DECLARE y int;
DECLARE z int;
DECLARE a int;
DECLARE b int;
DECLARE charid varchar(1);
DROP TEMPORARY TABLE IF EXISTS temp_nostaf;
CREATE TEMPORARY TABLE IF NOT EXISTS temp_nostaf (tempid INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY, char_id varchar(1));
INSERT INTO temp_nostaf (char_id) SELECT DISTINCT(LEFT(nostaf, 1)) FROM staf_new_no;
SET a = (SELECT min(tempid) FROM cms_psm.temp_nostaf ORDER BY tempid);
SET b = (SELECT COUNT(tempid) FROM cms_psm.temp_nostaf);
WHILE a<=b DO
SET charid = (SELECT char_id FROM cms_psm.temp_nostaf WHERE tempid=a);
SET x = (SELECT count(*) FROM staf_peribadi WHERE nostaf LIKE CONCAT('%', charid, '%') ORDER BY nostaf ASC);
SET y = (SELECT min(id) FROM staf_new_no WHERE nostaf LIKE CONCAT('%', charid, '%') ORDER BY nostaf ASC);
SET z = 1;
WHILE z<=x DO
UPDATE staf_new_no SET nostaf_new = CONCAT(charid, LPAD(z, 6, '0')) WHERE id=y;
SET z = z + 1 ;
SET y = y + 1 ;
END WHILE;
SET a = a + 1 ;
END WHILE;
END