用concat重命名Mysql表名 [英] Rename Mysql Table name with concat
本文介绍了用concat重命名Mysql表名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在MySQL中,我需要重命名带有后缀的表,该后缀可以标识上个月,并且我正在尝试使用以下语法来做到这一点:
In MySQL, I need to rename a table with a suffix which identifies previous month, and I'm trying to do that with this syntax:
RENAME TABLE 'myTable' TO CONCAT('myTable',DATE_FORMAT(CURRENT_DATE - INTERVAL 1 MONTH, '%Y_%m'));
Fe:我的表名是 customers,而我想要的是 customer_2015_04。
F.e: I've table name "customers" and what I want is "customer_2015_04".
问题在于concat订单。
The problem is with concat order.
我在做什么错了?
最诚挚的问候
推荐答案
我认为您需要使用准备好的语句来做到这一点:
I think you need to do this using a prepared statement:
set @sql = CONCAT('RENAME TABLE myTable TO myTable',
DATE_FORMAT(CURRENT_DATE - INTERVAL 1 MONTH, '%Y_%m')
);
prepare s from @sql;
execute s;
这篇关于用concat重命名Mysql表名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文