Reputation: 15
I'm trying to create a certain table but I get this error from Oracle:
ORA-00907: missing right parenthesis
I tried to look it up but found nothing similar...
This is what I'm trying to do:
CREATE TABLE Employees
(
EMPLOYEE_ID NUMBER NOT NULL GENERATED BY DEFAULT AS IDENTITY,
NAME VERCHAR2(30) NOT NULL,
PHONE_NUMBER VARCHAR(12) CHECK(PHONE_NUMBER LIKE '%%%-%%%-%%%%') NOT NULL,
SALARY NUMBER NOT NULL,
SENIORITY NUMBER NOT NULL,
PRIMARY KEY(EMPLOYEE_ID)
);
Upvotes: 0
Views: 238
Reputation: 147286
You have a few problems:
VERCHAR2
is a typo and should be changed to VARCHAR2
;CHECK
constraint allows for any value that has two hyphen's in it (e.g. x-y-z
) to be inserted into the phone number. You should use something like what he suggested i.e.REGEXP_LIKE(PHONE_NUMBER, '\d{3}-\d{3}-\d{4}')
NOT NULL
declaration on EMPLOYEE_ID
should be after the GENERATED
clause, not before it. Note you might actually wantGENERATED BY DEFAULT ON NULL AS IDENTITY
NULL
is inserted (instead of generating an error as your current definition will)Your query should be:
create table Employees
(
EMPLOYEE_ID NUMBER GENERATED BY DEFAULT AS IDENTITY NOT NULL,
NAME VARCHAR2(30) NOT NULL,
PHONE_NUMBER VARCHAR(12) CHECK(REGEXP_LIKE(PHONE_NUMBER, '\d{3}-\d{3}-\d{4}')) NOT NULL,
SALARY NUMBER NOT NULL,
SENIORITY NUMBER NOT NULL,
PRIMARY KEY(EMPLOYEE_ID)
);
Here's a demo on dbfiddle which also shows the effect of using GENERATED BY DEFAULT ON NULL AS IDENTITY
instead of GENERATED BY DEFAULT AS IDENTITY NOT NULL
.
Upvotes: 2