Ha1*_*wed 1 sql oracle-xe oracle10g
HY,
我试图在oracle中使用REGEXP_LIKE设置约束,但我一直在设置ORA-00920:无效的关系运算符
错误,这是我的代码(错误是在ck_files_name约束的末尾
CREATE TABLE files(
idFile INT PRIMARY KEY,
idParent INT REFERENCES files,
name VARCHAR2(256),
type CHAR(1),
CONSTRAINT ck_files_name CHECK REGEXP_LIKE(name, '[^\.]'), -- error ORA-00920: invalid relational operator
CONSTRAINT ck_files_type CHECK type IN ('d', 'f'),
CONSTRAINT ck_files_idFile_idParent CHECK (idFile <> idParent),
CONSTRAINT uq_files_idFile_name UNIQUE (idParent, name)
);
Run Code Online (Sandbox Code Playgroud)
我做错了什么,还是与我的oracle版本(oracle 10g xe)有关?
你必须在check关键字后加上parantheses .
以下工作,至少与Oracle 11,R2有关.
CREATE TABLE files(
idFile INT PRIMARY KEY,
idParent INT REFERENCES files,
name VARCHAR2(256),
type CHAR(1),
CONSTRAINT ck_files_name CHECK (REGEXP_LIKE(name, '[^\.]')),
CONSTRAINT ck_files_type CHECK (type IN ('d', 'f')),
CONSTRAINT ck_files_idFile_idParent CHECK (idFile <> idParent),
CONSTRAINT uq_files_idFile_name UNIQUE (idParent, name)
);
Run Code Online (Sandbox Code Playgroud)