如果存在则删除索引...如果存在则创建

时间:2013-11-05 08:14:22

标签: oracle oracle11g

在删除和创建索引之前,我想检查索引是否存在。

这可以通过简单的1-2行声明吗?

1 个答案:

答案 0 :(得分:2)

您当然可以查询dba_indexes / all_indexes / user_indexes以查看索引是否存在。假设您要查找特定的索引名称(您也可以在列集上匹配)

select count(*)
  into l_cnt
  from all_indexes
 where owner = <<owner of index>>
   and index_name = <<name of index>>

if( l_cnt > 0 )
then
  <<index exists>>
else
  <<index doesn't exist>>
end if;

当然,您也可以简单地删除索引并捕获它不存在的异常。