追加して、
SQL> conn scott/tiger SQL> set serveroutput on size 1000000 SQL> declare cursor cu is select to_char(add_months(to_date('200412','YYYYMM'),level),'YYYYMM') mon from dual connect by level <= 12*5+2; sql_stmt varchar2(500); begin for rec in cu loop sql_stmt := 'alter table T1 add pition P' || rec.mon ||' values (''' || rec.mon || ''')'; --dbms_output.put_line(sql_stmt); execute immediate sql_stmt; end loop; end; /
確認してみると、
SQL> set pagesize 0 SQL> select subobject_name from user_objects where object_name = 'T1'; P200501 P200502 P200503 P200504 P200505 P200506 P200507 P200508 P200509 P200510 P200511 P200512 P200601 P200602 P200603 P200604 P200605 P200606 P200607 P200608 P200609 P200610 P200611 P200612 P200701 P200702 P200703 P200704 P200705 P200706 P200707 P200708 P200709 P200710 P200711 P200712 P200801 P200802 P200803 P200804 P200805 P200806 P200807 P200808 P200809 P200810 P200811 P200812 P200901 P200902 P200903 P200904 P200905 P200906 P200907 P200908 P200909 P200910 P200911 P200912 P201001 P201002 63 rows selected. SQL> set pagesize 10000 SQL> col table_name for a10 SQL> col partition_position for 9999 SQL> col partition_name for a10 SQL> col high_value for a10 SQL> select table_name,partition_position,partition_name,high_value from user_tab_partitions where table_name='T1'; TABLE_NAME PARTITION_POSITION PARTITION_ HIGH_VALUE ---------- ------------------ ---------- ---------- T1 1 P200501 '200501' T1 2 P200502 '200502' T1 3 P200503 '200503' ...
おk。