MySQL预编译,创建 下一个月按日期命名的表prepare
create DATABASE mydb2
use mydb2
create PROCEDURE proc_13_prepare()
begin
DECLARE next_year int;
DECLARE next_month int;
DECLARE next_month_day int;
DECLARE next_month_str varchar(2);
declare next_month_day_str varchar(2);
DECLARE table_name_str varchar(10);
declare t_index int DEFAULT 1;
set next_year=year(date_add(now(),INTERVAL 1 month));
set next_month=month(date_add(now(),INTERVAL 1 month));
set next_month_day=dayofmonth(LAST_DAY(DATE_ADD(now(),INTERVAL 1 month)));
if next_month<10
then set next_month_str=concat('0',next_month);
else
set next_month_str=concat('',next_month);
end if;
WHILE t_index <= next_month_day DO
if(t_index<10)
then set next_month_day_str=concat('0',t_index);
else
set next_month_day_str=concat('',t_index);
end if;
set table_name_str=concat(next_year,'_',next_month_str,'_',next_month_day_str);
set @create_table_sql=concat(
'create table user_',table_name_str,'(`uid` int,`ename` varchar(50),`information` varchar(50))
collate=\'utf8_general_ci\' ENGINE=InnoDB');
prepare create_table_stmt from @create_table_sql;
execute create_table_stmt;
DEALLOCATE prepare create_table_stmt;
set t_index=t_index+1;
END WHILE;
end
select dayofmonth(LAST_DAY(DATE_ADD(now(),INTERVAL 1 month)));
call proc_13_prepare()
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?