Skip to Main Content
  • Questions
  • ORA-01502: index 'KRISHNA.PK_EMPNO' or partition of such index is in unusable state

Breadcrumb

Question and Answer

Chris Saxon

Thanks for the question, Balakrishna.

Asked: July 26, 2016 - 10:45 am UTC

Last updated: July 26, 2016 - 8:23 pm UTC

Version: 12c

Viewed 10K+ times! This question is

You Asked

HI TOM,

1)DESTINATION TABLE NAME IS:TEMP(EMPNO NUMBER(3) CONSTRAINT PK_EMPNO PRIMARY KEY,ENAME VARCHAR2(10),JOB VARCHAR2(10),SAL INTEGER)

I'M LOADING DATA FROM FLAT FILE into TEMP TABLE USING SQL*LOADER THROUGH DIRECT METHOD
FLAT FILE IS
--------------
1, MARTIN,SALESMAN , 1400
2,raghu,SALESMAN , 1400
3,kalam,scientist,1400
3,kalam,scientist , 10375
1, MARTIN,SALESMAN ,1400
1, MARTIN,SALESMAN ,1037
2,raghu,SALESMAN , 1400
3,kalam,scientist ,10375
3,kalam,scientist,1400
1, MARTIN, SALESMAN,,10375

After loading the above data into temp table in the database
Again i'm try to insert data into temp table in that particular schema i got an error
i.e(ERROR at line 1:
ORA-01502: index 'KRISHNA.PK_EMPNO' or partition of such index is in unusable state) how to resolve the issue, and i want to know what about the constraint primary key of temp table and how to enable it?

and Chris said...

Primary keys are supported by unique indexes.

If the index is unusable, you'll need to rebuild it:

SQL> create table t (
  2    EMPNO NUMBER(3) CONSTRAINT PK_EMPNO PRIMARY KEY,
  3    ENAME VARCHAR2(10),JOB VARCHAR2(10),SAL INTEGER
  4  ) partition by range (sal) interval (10) (
  5    partition p0 values less than (10),
  6     partition p1 values less than (20)
  7  );

Table created.

SQL> insert into t
  2    select rownum, 'Chris', 'Advocate', rownum from dual connect by level <= 20;

20 rows created.

SQL>
SQL> alter table t drop partition p0;

Table altered.

SQL>
SQL> select index_name, status from user_indexes
  2  where  table_name = 'T';

INDEX_NAME           STATUS
-------------------- --------
PK_EMPNO             UNUSABLE

SQL>
SQL> insert into t values (21, 'Chris', 'Advocate', 21);
insert into t values (21, 'Chris', 'Advocate', 21)
*
ERROR at line 1:
ORA-01502: index 'CHRIS.PK_EMPNO' or partition of such index is in unusable state


SQL>
SQL> alter index PK_EMPNO rebuild;

Index altered.

SQL>
SQL> select index_name, status from user_indexes
  2  where  table_name = 'T';

INDEX_NAME           STATUS
-------------------- --------
PK_EMPNO             VALID

SQL>
SQL> insert into t values (21, 'Chris', 'Advocate', 21);

1 row created.

Rating

  (1 rating)

Is this answer out of date? If it is, please let us know via a Comment

Comments

Direct path loading from SQL*Loader

Rajeshwaran, Jeyabal, July 27, 2016 - 2:22 pm UTC

When doing a Direct path loading from SQL*Loader, look into the log file, you can find more details.

Incase of duplicate data's in the Data file, the SQL-Loader utility set the index to "unusable" to success the data load.

.....
The following index(es) on table T were processed:
ORA-39828: Constraint T_PK was disabled because of index DEMO.T_PK error.
index DEMO.T_PK was made unusable due to:
ORA-01452: cannot CREATE UNIQUE INDEX; duplicate keys found
.....




demo@ORA12C> create table t(x int constraint t_pk primary key);

Table created.

demo@ORA12C> $sqlldr demo/demo@ora12c control=d:\ctl.txt log=d:\log.txt direct=Y

SQL*Loader: Release 12.1.0.2.0 - Production on Wed Jul 27 19:44:57 2016

Copyright (c) 1982, 2014, Oracle and/or its affiliates.  All rights reserved.

Path used:      Direct

Load completed - logical record count 4.

Table T:
  4 Rows successfully loaded.

Check the log file:
  d:\log.txt
for more information about the load.

demo@ORA12C> select * from t;

         X
----------
         1
         2
         3
         1

4 rows selected.

demo@ORA12C> column index_name format a10
demo@ORA12C> select index_name,status
  2  from user_indexes
  3  where table_name ='T' ;

INDEX_NAME STATUS
---------- --------
T_PK       UNUSABLE

1 row selected.

demo@ORA12C> $type d:\log.txt

SQL*Loader: Release 12.1.0.2.0 - Production on Wed Jul 27 19:44:57 2016

Copyright (c) 1982, 2014, Oracle and/or its affiliates.  All rights reserved.

Control File:   d:\ctl.txt
Data File:      d:\ctl.txt
  Bad File:     d:\ctl.bad
  Discard File:  none specified

 (Allow all discards)

Number to load: ALL
Number to skip: 0
Errors allowed: 50
Continuation:    none specified
Path used:      Direct

Table T, loaded from every logical record.
Insert option in effect for this table: TRUNCATE

   Column Name                  Position   Len  Term Encl Datatype
------------------------------ ---------- ----- ---- ---- ---------------------
X                                   FIRST     1           CHARACTER

The following index(es) on table T were processed:
ORA-39828: Constraint T_PK was disabled because of index DEMO.T_PK error.
index DEMO.T_PK was made unusable due to:
ORA-01452: cannot CREATE UNIQUE INDEX; duplicate keys found

Table T:
  4 Rows successfully loaded.
  0 Rows not loaded due to data errors.
  0 Rows not loaded because all WHEN clauses were failed.
  0 Rows not loaded because all fields were null.

Bind array size not used in direct path.
Column array  rows :    5000
Stream buffer bytes:  256000
Read   buffer bytes: 1048576

Total logical records skipped:          0
Total logical records read:             4
Total logical records rejected:         0
Total logical records discarded:        0
Total stream buffers loaded by SQL*Loader main thread:        2
Total stream buffers loaded by SQL*Loader load thread:        0

Run began on Wed Jul 27 19:44:57 2016
Run ended on Wed Jul 27 19:45:03 2016

Elapsed time was:     00:00:06.66
CPU time was:         00:00:00.07

demo@ORA12C> $type d:\ctl.txt
load data
infile *
into table t
truncate
(x)

begindata
1
2
3
1
demo@ORA12C>


More to Explore

VLDB

If you are new to partitioning, check out Connor McDonald's introduction series here.

VLDB

Documentation set on VLDB and Partitioning.