DELIMITER
D
R
O
P
P
R
O
C
E
D
U
R
E
I
F
E
X
I
S
T
S
‘
s
p
r
e
v
o
k
e
t
a
b
l
e
‘
DROP PROCEDURE IF EXISTS `sp_revoke_table`
DROPPROCEDUREIFEXISTS‘sprevoketable‘
CREATE DEFINER=root
@%
PROCEDURE sp_revoke_table
(p_table_name VARCHAR(100))
BEGIN
SET @t_tb_src = p_table_name;
SELECT CONCAT("create table _tmpdba like ", @t_tb_src) INTO @t_sql FROM DUAL;
PREPARE stmt_1 FROM @t_sql;
EXECUTE stmt_1;
DEALLOCATE PREPARE stmt_1;
SELECT CONCAT("_", @t_tb_src, "_", DATE_FORMAT(NOW(),'%Y%m%d_%H%i%s'), "_del") INTO @t_table_today FROM DUAL;
SELECT CONCAT("rename table ", @t_tb_src, " TO ",@t_table_today, ", _tmpdba to ", @t_tb_src ) INTO @t_sql FROM DUAL;
PREPARE stmt_2 FROM @t_sql;
EXECUTE stmt_2;
DEALLOCATE PREPARE stmt_2;
END$$
DELIMITER ;
完整实例:http://github.crmeb.net/u/defu
来自 “开源世界 ” ,链接:http://ym.baisou.ltd/post/620.html,如需转载,请注明出处,否则将追究法律责任。