简体   繁体   English

基于函数的索引在 oracle 12c 中不起作用

[英]functional based index not works in oracle 12c

I have a problem with oracle 12c when trying to create an functional based index.我在尝试创建基于函数的索引时遇到了 oracle 12c 的问题。 So I have a table like this:所以我有一张这样的表:

CREATE TABLE test_table(
    id integer PRIMARY KEY,
    delete_date DATE,
    msisdn varchar(20)
);

If delete_date is null then msisdn shall be unique.如果 delete_date 为空,则 msisdn 应是唯一的。 I found a solution here , but when I try it, ORA-02158: invalid CREATE INDEX option thrown.我在这里找到了一个解决方案,但是当我尝试它时,ORA-02158:抛出无效的 CREATE INDEX 选项。 Here is what I did:这是我所做的:

    CREATE UNIQUE INDEX test_table_msisdn_index 
ON test_table(CASE WHEN delete_date IS NULL THEN msisdn end);

CREATE UNIQUE INDEX test_table_msisdn_index 
ON test_table(CASE WHEN delete_date IS NULL THEN msisdn ELSE NULL end);

Also many sources like this says case statement can be used, but for me it not works.还有很多像这样的消息来源说可以使用 case 语句,但对我来说它不起作用。 How this logic can be implemented differently?这个逻辑如何以不同的方式实现? Please note, that unique constraint violated exception shall be thrown if duplicate msisdn inserted and delete_date is null.请注意,如果插入重复的 msisdn 并且 delete_date 为空,则将抛出唯一约束违反异常。 Thank for your attention and sorry for possibly duplicated question.感谢您的关注,并对可能重复的问题表示抱歉。

I don't know why, but problem was not in DBMS, problem was in my client.我不知道为什么,但问题不在于 DBMS,问题在于我的客户端。 I'm using DBeaver community 7.2.0 if run scripts in this client you'll get an ORA-02158: invalid CREATE INDEX option.我正在使用 DBeaver community 7.2.0,如果在此客户端中运行脚本,您将获得 ORA-02158: invalid CREATE INDEX 选项。 I tried it with jetbrains DataGrip and it works.我用 jetbrains DataGrip 尝试过它,它有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM