简体   繁体   中英

functional based index not works in oracle 12c

I have a problem with oracle 12c when trying to create an functional based index. 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. I found a solution here , but when I try it, ORA-02158: invalid CREATE INDEX option thrown. 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. 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. 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. I'm using DBeaver community 7.2.0 if run scripts in this client you'll get an ORA-02158: invalid CREATE INDEX option. I tried it with jetbrains DataGrip and it works.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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