【发布时间】:2011-11-02 16:58:32
【问题描述】:
我们的数据语义不区分大小写,因此我们将 oracle 会话配置为不区分大小写:
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 不支持 PK 约束的不区分大小写的语义?这在 MSSQL 中运行良好,它在处理排序规则方面具有更简单的方法。
当然,我们可以创建唯一索引而不是主键,但我想首先确保不支持执行此操作的常规方法。
我们的 oracle 版本是 11.2.0.1。
【问题讨论】:
标签: oracle