我必须删除超过364天的分区。 分区命名为“log_20110101”,因此分区的年龄大于 今天必须是
CONCAT('log_',TO_CHAR(SYSDATE -364,'YYYYMMDD'))
现在,如果我尝试这样的陈述,我会收到错误
ALTER TABLE LOG
DROP PARTITION CONCAT('log_',TO_CHAR(SYSDATE -364,'YYYYMMDD'));
-
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
答案 0 :(得分: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;