我们数据的语义是不区分大小写的,因此我们配置了Oracle会话来支持不区分大小写:
然而,这会遇到“ORA-00904: : invalid identifier”错误,因此我认为在PK定义中使用nlssort()函数是不可能的。 接下来尝试将大小写不敏感的唯一索引与主键关联:
alter session set NLS_COMP=LINGUISTIC;
alter session set NLS_SORT=BINARY_AI;
为了充分利用索引,我们还希望主键不区分大小写:
create table SCHEMA_PROPERTY (
NAME nvarchar2(64) not null,
VALUE nvarchar2(1024),
constraint SP_PK primary key (nlssort(NAME))
)
然而,这会遇到“ORA-00904: : invalid identifier”错误,因此我认为在PK定义中使用nlssort()函数是不可能的。 接下来尝试将大小写不敏感的唯一索引与主键关联:
create table SCHEMA_PROPERTY (
NAME nvarchar2(64) primary key using index (
create unique index SP_UQ on SCHEMA_PROPERTY(nlssort(NAME))),
VALUE nvarchar2(1024)
);
但这次也失败了:
Error: ORA-14196: Specified index cannot be used to enforce the constraint.
14196. 00000 - "Specified index cannot be used to enforce the constraint."
*Cause: The index specified to enforce the constraint is unsuitable
for the purpose.
*Action: Specify a suitable index or allow one to be built automatically.
我应该得出结论,Oracle不支持主键约束的大小写不敏感语义吗?这在MSSQL中可以正常工作,因为它在处理排序规则时有一个更简单的方法。
当然,我们可以创建一个唯一索引代替主键,但我想先确定正常的操作方式是否受到支持。
我们使用的Oracle版本是11.2.0.1。