Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Database > Oracle
|
Oracle General Oracle database discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Oracle section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 13th, 2003, 03:55 PM
Authorized User
 
Join Date: Nov 2003
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default How do you rebuild Index?

Hey guys, I'm still a little new to ORACLE, and I'm getting an ORACLE error: ORA-01502. I looked this error up and saw where people had stated that you need to "rebuild the index". How do you do that?
Thanks, any help would be appreciated.

Chris
 
Old November 19th, 2003, 10:55 PM
Authorized User
 
Join Date: Jul 2003
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Chris,

As the error message suggests, your index has become unusable (either thru dataload or some ddl statements). I'll recreate a possible scenario for you. Please look at the execution sequence below:

-----------------------------------------------------------------------------
SQL> create table t ( x number, v varchar2(10) );

Table created.

SQL> create index t_n1 on t ( x ) ;

Index created.

SQL> insert into t (x, v) values ( 1, 'a' );

1 row created.

SQL> insert into t (x, v) values ( 2, 'b' );

1 row created.

SQL> commit;

Commit complete.

SQL> select * from t where x = 2;

         X V
---------- ----------
         2 b

SQL> alter index t_n1 unusable; -- something like this has happened to your index

Index altered.

SQL> select * from t where x = 2; -- u try to access an unusable index
select * from t where x = 2
*
ERROR at line 1:
ORA-01502: index 'C5489.T_N1' or partition of such index is in unusable state

SQL> alter index t_n1 rebuild; -- now rebuild the index

Index altered.

SQL> select * from t where x = 2;

         X V
---------- ----------
         2 b

SQL>

-----------------------------------------------------------------------------

You need to find out which index is being accessed and rebuild it. You may get the information about the status of the index as follows:

-----------------------------------------------------------------------------
SQL> select index_name, status from user_indexes where index_name = 'T_N1' ;

INDEX_NAME STATUS
------------------------------ --------
T_N1 VALID

SQL> alter index t_n1 unusable;

Index altered.

SQL> select index_name, status from user_indexes where index_name = 'T_N1' ;

INDEX_NAME STATUS
------------------------------ --------
T_N1 UNUSABLE

SQL>
-----------------------------------------------------------------------------

You may refer to some excellent information on indexes in the Oracle documentation - "Oracle 8i Administrator's guide" and "Designing and tuning for performance".

Hope that helps.

Cheers,
Prat







Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating Index carumuga SQL Server 2000 1 September 26th, 2008 04:10 PM
Index carumuga SQL Server 2000 1 December 31st, 2007 12:42 PM
Rebuild All: 2 succeeded, 20 failed, 0 skipped kingw BOOK: ASP.NET Website Programming Problem-Design-Solution 2 December 30th, 2004 05:39 PM
HELP ! After first rebuild I get error? kamarkh BOOK: ASP.NET Website Programming Problem-Design-Solution 2 March 23rd, 2004 01:44 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.