Conditional unique constraint with multiple fields in oracle db

后端 未结 3 754
一个人的身影
一个人的身影 2021-01-04 05:12

I have this table:

XPTO_TABLE (id, obj_x, date_x, type_x, status_x)

I wanna create a unique constraint that applies to the fields (ob

3条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-04 05:54

    Because the CREATE UNIQUE INDEX is expecting only a value you can concatenate the columns as follow

    CREATE UNIQUE INDEX UN_OBJ_DT_TYPE_STATUS
    ON XPTO_TABLE(
    (CASE
         WHEN STATUS_X <> 5
             THEN OBJ_X || TO_CHAR (DATE_X, 'dd/MM/yyyy') || TYPE_X
         ELSE
             NULL
     END));
    

提交回复
热议问题