Oracle - 仅在不存在时创建索引

标签 oracle database-indexes

只有当索引不存在时,有没有办法在 oracle 中创建索引?

就像是

CREATE INDEX IF NOT EXISTS ord_customer_ix
   ON orders (customer_id);

最佳答案

仅在不存在时添加索引:

declare 
  already_exists  exception; 
  columns_indexed exception;
  pragma exception_init( already_exists, -955 ); 
  pragma exception_init(columns_indexed, -1408);
begin 
  execute immediate 'create index ord_customer_ix on orders (customer_id)'; 
  dbms_output.put_line( 'created' ); 
exception 
  when already_exists or columns_indexed then 
  dbms_output.put_line( 'skipped' );  
end;     

关于Oracle - 仅在不存在时创建索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44539663/

相关文章:

javascript - Node.js Oracle DB 日期返回错误值

oracle - 在没有业务限制的情况下,我应该为 Oracle 字符类型设置什么限制?

sql - 从 SQL 查询制作图表的工具

xml - PLSQL XMLTable XPath 获取最深深度的所有标签

postgresql - Text[] 数组列的表索引

SQL ORACLE - 查找连续天数

sql-server-2008 - SQL Server 2008 : How to count all indexes on all tables in Database?

java - 我是否需要在使用它的每个微服务(模块)中或仅在根应用程序中定义数据存储索引?

c# - EF6 codefirst 中唯一的多列

database - 在使用两个字段进行查询时,索引 postgres 表的正确方法是什么?