使用存储过程在MYSQL中将一个表的内容复制到另一个表

时间:2014-12-12 02:53:45

标签: mysql stored-procedures copy

我正在尝试创建一个存储过程来将表的整个内容复制到另一个

CREATE PROCEDURE copytbl
BEGIN
INSERT INTO `comparison2` (`id`, `Split/Skil`, `Skill State`, `Agents Staffed`, `Calls Waiting`, `Oldest Call Waiting`, `ACD Calls`, `Avg ACD Time`, `Aban Calls`, `Avg Aban Time`, `Avg Speed Ans`, `ABANDON30`)
SELECT * FROM `comparison`
END

两个表都具有相同的格式,我在尝试创建过程时不断收到此错误:

  

1064 - 您的SQL语法出错;检查与MySQL服务器版本对应的手册,以获得正确的语法

     

靠近'BEGIN INSERT INTO comparison2idSplit/SkilSkill State,`代理商Sta'在第2行

1 个答案:

答案 0 :(得分:1)

使用此:

DELIMITER $$
DROP PROCEDURE IF EXISTS copytbl$$
CREATE PROCEDURE copytbl()
BEGIN
    INSERT INTO `comparison2` (`id`, `Split/Skil`, `Skill State`, `Agents Staffed`, `Calls Waiting`, `Oldest Call Waiting`, `ACD Calls`, `Avg ACD Time`, `Aban Calls`, `Avg Aban Time`, `Avg Speed Ans`, `ABANDON30`)
    SELECT * FROM `comparison`;
END$$
DELIMITER ;

执行程序:

CALL copytbl();