oracle drop index if exists

前端 未结 5 1669
渐次进展
渐次进展 2020-12-28 13:53

How do you drop an index only if it exists?

It seems simple but I did found anything on the net. The idea is to drop it only if it exists, because if not, I will hav

5条回答
  •  孤独总比滥情好
    2020-12-28 14:26

    DECLARE
       COUNT_INDEXES   INTEGER;
    BEGIN
       SELECT COUNT ( * )
         INTO COUNT_INDEXES
         FROM USER_INDEXES
        WHERE INDEX_NAME = 'myIndexName';
       -- Edited by UltraCommit, October 1st, 2019
       -- Accepted answer has a race condition.
       -- The index could have been dropped between the line that checks the count
       -- and the execute immediate
       IF COUNT_INDEXES > 0
       THEN
          EXECUTE IMMEDIATE 'DROP INDEX myIndexName';
       END IF;
    END;
    /
    

提交回复
热议问题