我是SQL新手,我正在尝试找出当我尝试按照帖子here中的建议在我的列中仅强制执行一个'是'时收到的错误消息。
DROP TABLE team CASCADE CONSTRAINTS PURGE;
create table team (
name varchar2(4) NOT NULL UNIQUE,
isTeamLead char(3)
check (isTeamLead in ('Yes')));
create unique index only_one_yes on team(isTeamLead)
(case when col='YES' then 'YES' end);
错误报告如下:
Error report -
SQL Error: ORA-02158: invalid CREATE INDEX option
02158. 00000 - "invalid CREATE INDEX option"
*Cause: An option other than COMPRESS, NOCOMPRESS, PCTFREE, INITRANS,
MAXTRANS, STORAGE, TABLESPACE, PARALLEL, NOPARALLEL, RECOVERABLE,
UNRECOVERABLE, LOGGING, NOLOGGING, LOCAL, or GLOBAL was specified.
*Action: Choose one of the valid CREATE INDEX options.
有什么想法吗?
运行Oracle Database 11g企业版11.2.0.1.0版
答案 0 :(得分:1)
删除case
语句的create index
部分。这执行OK:
create table team (
name varchar2(4) NOT NULL UNIQUE,
isTeamLead char(3) check (isTeamLead in ('Yes'))
);
create unique index only_one_yes on team(isTeamLead);
insert into team values ('x', 'Yes');
insert into team values ('y', null);
请参阅SQLFiddle。