【发布时间】:2019-11-02 03:52:51
【问题描述】:
我有一个包含三列的表 - c_id、o_id、f_id。只要 f_id 不为 3,三个 id 的组合就必须是唯一的。
在阅读了类似的问题后,我尝试了以下方法:
create unique index my_index on my_table (
decode (f_id, !3, c_id, null),
decode (f_id, !3, o_id, null),
decode (f_id, !3, f_id, null));
但我得到一个 missing expression 错误。我也试过
create unique index my_index on my_table ((
case
when f_id <> 3 then c_id
when f_id <> 3 then o_id
when f_id <> 3 then f_id
else null
end));
但是对于这个我得到无法创建索引;发现重复键
原来我试过
when f_id <> 3 then (c_id, o_id, f_id)
但这根本不起作用。
无论如何,索引可能有问题,因为表似乎没有任何重复项,我没有得到任何记录
select c_id, o_id, f_id, count(*) as dupes
from my_table
where f_id <> 3
having count(*) > 1
group by c_id, o_id, f_id;
我对这些 FBI 有点盲目,因此我们将不胜感激。
【问题讨论】: