Thursday, March 28, 2019

script to generate partition names


with dts as (
  select date'2013-01-01'+rownum-1 dt from dual
  connect by level <= 366
)
  select 'PARTITION' || 'P_BEFORE' || '_' || TO_CHAR(dt, 'YYYYMMDD') || 'VALUES LESS THAN (' || TO_CHAR(dt, 'YYYYMMDD') || ')'||  ';' from dts
  where  to_char(dt, 'FMDAY') = 'SATURDAY';
 

OUTPUT;
PARTITIONP_BEFORE_20130105VALUES LESS THAN (20130105);
PARTITIONP_BEFORE_20130112VALUES LESS THAN (20130112);
PARTITIONP_BEFORE_20130119VALUES LESS THAN (20130119);
PARTITIONP_BEFORE_20130126VALUES LESS THAN (20130126);
PARTITIONP_BEFORE_20130202VALUES LESS THAN (20130202);
PARTITIONP_BEFORE_20130209VALUES LESS THAN (20130209);
PARTITIONP_BEFORE_20130216VALUES LESS THAN (20130216);
PARTITIONP_BEFORE_20130223VALUES LESS THAN (20130223);
PARTITIONP_BEFORE_20130302VALUES LESS THAN (20130302);


In case you have to generate a list of partitions we can use this method to auto generate partitions.

No comments:

Post a Comment