Oracle约束 [英] Oracle constraint
本文介绍了Oracle约束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我可以添加一个检查约束来确保所有值都是唯一的,但允许重复默认值吗?
Can I add a check constraint which makes sure that all values are unique, but allow duplicates of a default value?
推荐答案
您可以使用基于函数的索引(FBI)来实现此目标:
You can achieve this using a funcction-based index (FBI):
create unique index idx on my_table (case when col != 'DEFAULT' then col end));
这会在除"DEFAULT"以外的所有值上创建唯一索引.
That creates a unique index on all values except 'DEFAULT'.
这篇关于Oracle约束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文