当删除分区和更新全局索引存在时错误:分区维护操作可能无法与其他操作结合使用

时间:2018-07-17 07:18:48

标签: oracle partitioning

在这里,我编写了一个Oracle SP来删除分区并更新全局索引。 但它遇到了错误

begin
EXECUTE IMMEDIATE 'alter session set nls_date_format="YYYY-MM-DD"';
dbms_output.put_line(need_housekeeping_month);

EXECUTE IMMEDIATE 'ALTER TABLE pos_data DROP PARTITION FOR (need_housekeeping_month))  UPDATE GLOBAL INDEXES';

end;

我搜索了一些解决方案,但对此一无所知,请帮忙。

 ORA-14048: a partition maintenance operation may not be combined with other operations

        Cause: The ALTER TABLE or ALTER INDEX statement attempted to combine a partition maintenance operation (for example, MOVE PARTITION) with some other operation (for example, ADD PARTITION or PCTFREE) which is illegal.

        Action: Ensure that a partition maintenance operation is the sole operation specified in an 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) can be combined.

添加另一个问题

    create or replace procedure   SP_HOUSE_KEEPING(p_dt_cycle_dt in VARCHAR2) is
hotspot_data_months number :=27;
need_housekeeping_month DATE := ADD_MONTHS( to_date(p_dt_cycle_dt,'yyyymmdd'), -(hotspot_data_months-1) );
begin
EXECUTE IMMEDIATE 'alter session set nls_date_format="YYYY-MM-DD"';
dbms_output.put_line(need_housekeeping_month);
EXECUTE IMMEDIATE 'ALTER TABLE pos_data DROP PARTITION FOR (need_housekeeping_month)  UPDATE GLOBAL INDEXES';
end;

ORA-14755:FOR VALUES子句的分区规范无效。

1 个答案:

答案 0 :(得分:1)

您不能将分区设置为变量,请尝试以下操作:

EXECUTE IMMEDIATE 'ALTER TABLE pos_data DROP PARTITION FOR (DATE '''||to_char(need_housekeeping_month, 'YYYY-MM-DD')||''') UPDATE GLOBAL INDEXES';