[英]Create Unqiue case-insensitive constraint on two varchar fields
In Oracle 10g, how do I add a unique case-insensitive constraint on two varchar fields? 在Oracle 10g中,如何在两个varchar字段上添加唯一的不区分大小写的约束? For example, given the following records already in the table:
例如,给定表中已有的以下记录:
"Stephen", "Swensen"
"John", "Smith"
The following inserts would be invalid: 以下插入无效:
"stephen", "Swensen"
"John", "smith"
"stephen", "swensen"
But the following inserts would be valid: 但是以下插入是有效的:
"Stephen", "Smith"
"John", "Swensen"
I've managed to get it working by doing: 我已经设法让它工作:
CREATE UNIQUE INDEX person_name_upper ON person(
UPPER(first_name), UPPER(last_name));
Assuming your table is called person , and the first and last name columns are called first_name and last_name , add this unique constraint: 假设您的表名为person ,并且名字和姓氏列名为first_name和last_name ,请添加以下唯一约束:
ALTER TABLE person ADD CONSTRAINT person_name_unique
UNIQUE(LOWER(first_name),LOWER(last_name));
Let me know if I understood your question correctly and made the correct assumptions about your table layout. 如果我正确理解您的问题并对您的表格布局做出正确的假设,请告诉我。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.