The semantic of our data is case insensitive, so we configure the oracle sessions to be case insensitive:
alter session set NLS_COMP=LINGUISTIC;
alter session set NLS_SORT=BINARY_AI;
Then, to take advantage of indexes we would also want the primary key to be case insensitive as well:
create table SCHEMA_PROPERTY (
NAME nvarchar2(64) not null,
VALUE nvarchar2(1024),
constraint SP_PK primary key (nlssort(NAME))
)
However, this runs into “ORA-00904: : invalid identifier”, so I assume it is not possible to use the nlssort() function in the PK definition.
Next attempt was to associate a case-insensitive unique index to the primary key:
create table SCHEMA_PROPERTY (
NAME nvarchar2(64) primary key using index (
create unique index SP_UQ on SCHEMA_PROPERTY(nlssort(NAME))),
VALUE nvarchar2(1024)
);
but this failed too:
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.
Should I just conclude that Oracle does not support case-insensitive semantics for a PK constraint? This works fine in MSSQL which has a simpler approach in dealing with collations.
We could, of course, create a unique index instead of the primary key, but I wanted to make sure first that the normal way to do this is not supported.
Our oracle version is 11.2.0.1.
As you are on 11.2 you can use a virtual column to achieve this: