Example of Oracle Partition Table usage:
Create or replace procedure bl_partition is
V_ SQL varchar (1024 );
V_count int;
V_partname varchar2 (32 );
V_startdate date;
V_enddate date: = trunc (sysdate) + 1;
Begin
V_ SQL: = 'select count (*) from user_tables where table_name = ''bl _ test ''';
Execute immediate v_ SQL
Into v_count;
If v_count = 0 then
V_ SQL: = 'create table bl_test (period date, abcd varchar2 (20) nologging partition by range (period)
(Partition pmax values less than (MAXVALUE) tablespace bl_test )';
Execute immediate v_ SQL;
End if;
V_ SQL: = 'select max (partition_name) from user_tab_partitions where table_name = ''bl _ test'' and partition_name <> ''pmax ''';
Execute immediate v_ SQL
Into v_partname;
If v_partname is null then
V_startdate: = trunc (sysdate)-2;
Else
V_startdate: = to_date (substr (v_partname, 2), 'yyyymmdd ');
End if;
While v_startdate <v_enddate loop
V_startdate: = v_startdate + 1;
V_partname: = 'P' | to_char (v_startdate, 'yyyymmdd ');
V_ SQL: = 'alter table bl_test split partition pmax at (to_date (''' |
To_char (v_startdate + 1, 'yyymmdd') |
''', ''Yyyymmdd'') into (partition '| v_partname |
', Partition pmax )';
Execute immediate v_ SQL;
End loop;
End bl_partition;