mysql创建存储过程动态SQL语句

DROP PROCEDURE IF EXISTS x.`wk`;
DELIMITER $$
CREATE PROCEDURE `x`.`wk`()
BEGIN
DECLARE crs VARCHAR ( 500 );
DECLARE t VARCHAR ( 50 ); SET t = CONCAT( "t_track_recording_", YEAR ( CURRENT_DATE ) );
SET crs = CONCAT( "CREATE TABLE IF NOT EXISTS ", t, " like t_track_recording; " ); SET @sql = crs;
PREPARE stmt FROM @sql; -- 预处理动态sql语句
EXECUTE stmt ; -- 执行sql语句
DEALLOCATE PREPARE stmt; -- 释放prepare END$$ CALL `x`.`wk`()

记得一定要定义delimiter $$

上一篇:svn 提交错误 400 Bad Reqest MKACTIVITY 请求于XX失败 Conflict Unable to connect to a repository at URL


下一篇:wikioi 1076 排序 【这里含冒泡、选择、插入以及快排库函数的调用】