本篇内容主要讲解“ORACLE分区索引UNUSABLE导致的DML操作失败举例分析”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“ORACLE分区索引UNUSABLE导致的DML操作失败举例分析”吧!
1、创建模拟的分区表
SQL> CREATE TABLE T_NEW (ID int, TIME date,name varchar2(20)) PARTITION BY RANGE (TIME)
(PARTITION P1 VALUES LESS THAN (TO_DATE('2018-1-1', 'YYYY-MM-DD')),
PARTITION P2 VALUES LESS THAN (TO_DATE('2018-2-1', 'YYYY-MM-DD')),
PARTITION P3 VALUES LESS THAN (TO_DATE('2018-3-1', 'YYYY-MM-DD')),
PARTITION P4 VALUES LESS THAN (MAXVALUE)); 2 3 4 5
Table created.
SQL>
2、插入数据测试分区表可用
SQL> insert into t_new values(1,TO_DATE('2018-1-15', 'YYYY-MM-DD'),'hellow');
1 row created.
SQL>
SQL> commit;
Commit complete.
SQL> select * from t_new;
ID TIME NAME
---------- --------- --------------------
1 15-JAN-18 hellow
SQL>
3、创建业务变更的不可见不可用分区索引
SQL> create unique index IDX1 on t_new (id, time) local invisible nologging unusable;
Index created.
SQL>
4、执行INSERT插入失败,提示:ORA-01502分区索引状态为不可用
SQL> insert into t_new values(1,TO_DATE('2018-3-15', 'YYYY-MM-DD'),'yellow');
insert into t_new values(1,TO_DATE('2018-3-15', 'YYYY-MM-DD'),'yellow')
*
ERROR at line 1:
ORA-01502: index 'TEST.IDX1' or partition of such index is in unusable state
SQL>
5、重新创建索引去掉UNUSABLE关键字
SQL> drop index idx1;
Index dropped.
SQL> create unique index IDX1 on t_new (id, time) local invisible nologging ;
Index created.
SQL>
6、模拟INSERT插入不受影响
SQL> insert into t_new values(1,TO_DATE('2018-3-15', 'YYYY-MM-DD'),'yellow');
1 row created.
SQL>
到此,相信大家对“ORACLE分区索引UNUSABLE导致的DML操作失败举例分析”有了更深的了解,不妨来实际操作一番吧!这里是亿速云网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!