create PROCEDURE Usp_Partition()
BEGIN
DECLARE _time datetime;
DECLARE num int;
DECLARE _p VARCHAR(20)DEFAULT p;
DECLARE p1 VARCHAR(20);
/* 获取下一个月的第一天*/
select date_add(curdate()-day(curdate())+1,interval 1 month)as _time;
/*将时间中的‘-’去掉*/
SELECT REPLACE(_time,‘-‘,‘‘)as num;
SELECT _p+num as p1;
SET concat(‘alter table book8 ADD PARTITION (PARTITION p‘,p1,‘ VALUES LESS THAN (TO_DAYS (‘‘‘,YEARWEEK(p1),‘‘‘)))‘);
END
查询所有分区
select
partition_name part,
partition_expression expr,
partition_description descr,
table_rows
from information_schema.partitions where
table_schema = schema()
and table_name=‘book9‘;
时间: 2024-10-12 07:34:54