2011-06-22 8 views
2

364日より古いパーティションを削除する必要があります。生成されたパラメータとしてパーティション名を持つoracleパーティションを削除する方法

- 今日 よりも古いパーティションは、私は、そのような声明をしようとすると、今私は、エラー

ALTER TABLE LOG 
DROP PARTITION CONCAT('log_',TO_CHAR(SYSDATE -364,'YYYYMMDD')); 

を取得

CONCAT('log_',TO_CHAR(SYSDATE -364,'YYYYMMDD'))

する必要がありますので、 パーティションは、「log_20110101」と命名されています

Error report: 
SQL Error: ORA-14048: a partition maintenance operation may not be combined with other operations 
14048. 00000 - "a partition maintenance operation may not be combined with other operations" 
*Cause: ALTER TABLE or ALTER INDEX statement attempted to combine 
      a partition maintenance operation (e.g. MOVE PARTITION) with some 
      other operation (e.g. ADD PARTITION or PCTFREE which is illegal 
*Action: Ensure that a partition maintenance operation is the sole 
      operation specified in ALTER TABLE or ALTER INDEX statement; 
      operations other than those dealing with partitions, 
      default attributes of partitioned tables/indices or 
      specifying that a table be renamed (ALTER TABLE RENAME) may be 
      combined at will 

答えて

5

パーティション名は、SQL文を発行するときに修正する必要があります。表現してはいけない。 USER_TAB_PARTITIONSテーブルを反復処理して、どのパーティションを削除するかを決定し、実際に削除する動的SQLを構築するようなことができるはずです。

DECLARE 
    l_sql_stmt VARCHAR2(1000); 
    l_date  DATE; 
BEGIN 
    FOR x IN (SELECT * 
       FROM user_tab_partitions 
      WHERE table_name = 'LOG') 
    LOOP 
    l_date := to_date(substr(x.partition_name, 5), 'YYYYMMDD'); 
    IF(l_date < add_months(trunc(sysdate), -12)) 
    THEN 
     l_sql_stmt := 'ALTER TABLE log ' || 
        ' DROP PARTITION ' || x.partition_name; 
     dbms_output.put_line(l_sql_stmt); 
     EXECUTE IMMEDIATE l_sql_stmt; 
    END IF; 
    END LOOP; 
END; 
関連する問題