oracle drop index如果存在 [英] oracle drop index if exists
本文介绍了oracle drop index如果存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果索引存在,你如何删除索引?
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 have an error and my process stops.
我发现这是为了找到索引存在:
I found this to find if the index exists:
select index_name
from user_indexes
where table_name = 'myTable'
and index_name='myIndexName'
但我不知道怎么把它与
But I don't know how to put it together with
DROP INDEX myIndexName
推荐答案
DECLARE
COUNT_INDEXES INTEGER;
BEGIN
SELECT COUNT(*) INTO COUNT_INDEXES
FROM USER_INDEXES
WHERE INDEX_NAME = 'myIndexName';
IF COUNT_INDEXES > 0 THEN
EXECUTE IMMEDIATE 'DROP INDEX myIndexName';
END IF;
END;
/
这篇关于oracle drop index如果存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文