user365268
user365268

Reputation:

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

error, here is my code (the error is at the end of the ck_files_name constraint

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

Upvotes: 2

Views: 4945

Answers (2)

Chandu
Chandu

Reputation: 82893

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

Upvotes: 0

Ren&#233; Nyffenegger
Ren&#233; Nyffenegger

Reputation: 40499

You have to put parantheses after the check keyword.

The following works, at least with 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)
);

Upvotes: 6

Related Questions