×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

I need to delete an index ONLY if it exists and NOT return 'not found
2

I need to delete an index ONLY if it exists and NOT return 'not found

I need to delete an index ONLY if it exists and NOT return 'not found

(OP)
I have a need to determine if an index exists, delete it if it does, and then create a new index with the same name.  Due to the install script being used at our site, I cannot allow an 'index not found' to be returned (that will kill my install).  existing code is in the following form:

  drop index XXXXX;
   create bitmap index XXXXX ~~~~~~;

I need to "wrapper" the drop index statement to process only if the index exists.

Any help is greatly appreciated.

RE: I need to delete an index ONLY if it exists and NOT return 'not found

Hi,

Can you put DDL (create etc) statements in a PL/SQL Block?

If you can you could write some PL/SQL to look up the index in the data dictionary (can't remember the table name and I'm not somewhere I can look at the moment, but I will if you need me to) and only create it if it doesn't already exist.

Mike

Mike Lacey
Mike_Lacey@Cargill.Com
Cargill's Corporate Web Site

RE: I need to delete an index ONLY if it exists and NOT return 'not found

(OP)
Mike,

Thanks to you, sir.  Mislabeled as a 'programmer' - and I still have very little Oracle knowledge.  Any rough outline is appreciated.  I can work with whatever you can provide as a starting shell for design.

Terry

RE: I need to delete an index ONLY if it exists and NOT return 'not found

2
You can't use DDL directly from PL/SQL.  However, you can use the DBMS_SQL package to do this.  Long ago, I got tired of trying to remember exactly how this works, so I wrote the following procedure (which only works for real simple commands!):

PROCEDURE dynamic_statement(in_command VARCHAR2)
AS
v_cursor_handle INTEGER;
v_feedback INTEGER;

BEGIN

v_cursor_handle := DBMS_SQL.OPEN_CURSOR;
DBMS_SQL.PARSE(v_cursor_handle, in_command,DBMS_SQL.NATIVE);
v_feedback := DBMS_SQL.EXECUTE(v_cursor_handle);

END;

Now if I want to create an index from within a PL/SQL block, all I need to do is:

BEGIN
.
.
.
DYNAMIC_STATEMENT('CREATE INDEX abc on my_table(col1)');
.
.
.
END;

RE: I need to delete an index ONLY if it exists and NOT return 'not found

(OP)
CARP,

You are a gem.  Thank you sir (or Madam).  Your assistance is greatly appreciated and, like Mike, I plan to use this puppy to death.

Terry

RE: I need to delete an index ONLY if it exists and NOT return 'not found

Mr. Lacey -
How on earth can you nick that which is freely given?
Glad to help.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close