![](/img/trans.png)
[英]Unique value Constraint with multiple columns across the table, not the combination in Oracle
[英]Unique index/constraint on 2 columns in same table in Oracle
我需要在表中的 2 列上创建唯一约束/索引。 这两列之一可以为null
。 我的唯一约束/索引需要检查这 2 列是否不为空,然后它们不能重复。
不确定如何解决这个问题,任何初学者?
您可以为此使用主键和基于函数的索引。 这是一个例子:
create table t (
id int primary key,
x int,
y int
);
create unique index t_x_y on t(x, y, (case when x is null or y is null then id end));
这是一个 db<>fiddle。
尝试在索引/约束中的列上使用 NVL 函数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.