标签:
DECLARE V_SQL VARCHAR2(1000); V_SQL_HEAD VARCHAR2(100); V_SQL_TAIL VARCHAR2(10); V_DAY VARCHAR2(8); CURSOR C_CUR IS SELECT TO_CHAR((TO_DATE(‘2012-01‘, ‘yyyy-mm‘) + (ROWNUM - 1)), ‘YYYYMMDD‘) S_DATE FROM DUAL CONNECT BY ROWNUM <= LAST_DAY(TO_DATE(‘2012-12‘, ‘yyyy-mm‘)) - TO_DATE(‘2012-01‘, ‘yyyy-mm‘) + 1; BEGIN DBMS_OUTPUT.ENABLE(1000000); OPEN C_CUR; V_SQL_HEAD := ‘PARTITION BY RANGE(ACCT_DAY)‘ || CHR(13) || ‘(‘; V_SQL_TAIL := CHR(13) || ‘)‘; DBMS_OUTPUT.PUT_LINE(V_SQL_HEAD); LOOP FETCH C_CUR INTO V_DAY; EXIT WHEN C_CUR%NOTFOUND; V_SQL := ‘PARTITION PART_‘ || V_DAY || ‘ ‘ || ‘VALUES LESS THAN (‘‘‘ || TO_CHAR((TO_DATE(V_DAY, ‘YYYYMMDD‘) + 1), ‘YYYYMMDD‘) || ‘‘‘)‘; DBMS_OUTPUT.PUT_LINE(V_SQL); END LOOP; DBMS_OUTPUT.PUT_LINE(V_SQL_TAIL); CLOSE C_CUR; END;
该语句执行之后的效果就是生成了2012年一年的分区,不重不漏。具体情况具体修改。勿喷。
标签:
原文地址:http://my.oschina.net/u/2273085/blog/415329