简体   繁体   English

甲骨文检查regexp_like

[英]oracle check regexp_like

hy, 嗨,

I am trying to put a constraint with REGEXP_LIKE in oracle, but i keep geting a ORA-00920: invalid relational operator 我试图在Oracle中使用REGEXP_LIKE施加约束,但我不断收到ORA-00920:无效的关系运算符

error, here is my code (the error is at the end of the ck_files_name constraint 错误,这是我的代码(错误位于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)
);

Am I doing something wrong, or does it have to do with my oracle version (oracle 10g xe) ? 我是在做错什么,还是与我的oracle版本(oracle 10g xe)有关?

You have to put parantheses after the check keyword. 您必须在check关键字后放置括号。

The following works, at least with Oracle 11, R2. 以下至少在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)
);

Paranthesis is missing. 缺少了寄生。 Try this: 尝试这个:

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)
);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM