gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 04:52:43 25 4
gpt4 key购买 nike

只有当索引不存在时,有没有办法在 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com