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'; 

 

相关文章:

  • 2021-09-21
  • 2022-12-23
  • 2022-12-23
  • 2021-11-16
  • 2021-11-19
猜你喜欢
  • 2021-10-19
  • 2021-11-26
  • 2022-12-23
  • 2022-12-23
  • 2021-05-29
  • 2022-12-23
  • 2021-09-11
相关资源
相似解决方案