CREATE TABLE ADMIN (
A_EMP_ID CHAR 5 BYTE NOT NULL,
ADMIN_START_DATE DATE DEFAULT SYSDATE NOT NULL,
ADMIN_END_DATE DATE NULL,
DIVERSITY_TRAINING_CERT CHAR(1 BYTE) DEFAULT 'N' NOT NULL,
ADMIN_TITLE CHAR(40 BYTE) NULL,
CONSTRAINT ADMIN_PK PRIMARY KEY(A_EMP_ID),
CONSTRAINT ADMIN_FK1
FOREIGN KEY(A_EMP_ID)
REFERENCES ADMIN(A_EMP_ID),
CONSTRAINT ADMIN_DIVERSITY_CERT
CHECK (DIVERSITY_TRAINING_CERT = 'N','Y'),
CONSTRAINT ADMIN_END_DATE
CHECK (<= 'ADMIN_START_DATE'),
);
Error starting at line : 1 in command -
CREATE TABLE ADMIN (
A_EMP_ID CHAR 5 BYTE NOT NULL,
ADMIN_START_DATE DATE DEFAULT SYSDATE NOT NULL,
ADMIN_END_DATE DATE NULL,
DIVERSITY_TRAINING_CERT CHAR(1 BYTE) DEFAULT 'N' NOT NULL,
ADMIN_TITLE CHAR(40 BYTE) NULL,
CONSTRAINT ADMIN_PK PRIMARY KEY(A_EMP_ID),
CONSTRAINT ADMIN_FK1
FOREIGN KEY(A_EMP_ID)
REFERENCES ADMIN(A_EMP_ID),
CONSTRAINT ADMIN_DIVERSITY_CERT
CHECK (DIVERSITY_TRAINING_CERT = 'N','Y'),
CONSTRAINT ADMIN_END_DATE
CHECK (<= 'ADMIN_START_DATE'),
)
Error report -
SQL Error: ORA-00907: missing right parenthesis
00907. 00000 - "missing right parenthesis"
*Cause:
*Action:
The top part is my code and when I run it, I get the message from the bottom half. I'm thinking it's something to do with my foreign key, but I don't know what the exact solution is. Any help is greatly appreciated.
CHAR 5 BYTE should be CHAR (5 BYTE) (but CHAR should not be used anyway try VARCHAR2 or NVARCHAR2...)
and the constraint <= 'ADMIN_START_DATE' is incorrect. This should have two values to compare
There is a lot wrong with your statement.
A_EMP_ID CHAR 5 BYTE
is missing the(..)
around the length constraintCHAR
for theadmin_title
. UseVARCHAR2
instead.DIVERSITY_TRAINING_CERT = 'N','Y'
is not a valid expression. You probably wantdiversity_training_cert IN ('N','Y')
FOREIGN KEY (a_emp_id) REFERENCES admin(a_emp_id)
is syntactically correct, it doesn't makes sense. I guess you want amanager_id
or something similar. And then something likeFOREIGN KEY (manager_id) REFERENCES admin(a_emp_id)
.Alternatively you maybe intended to reference an
employee
table. In that case thea_emp_id
data type must match the type of PK column that table.CONSTRAINT ADMIN_END_DATE CHECK (<= 'ADMIN_START_DATE'),
has three errors:admin_start_date
not'admin_start_date'
<= admin_start_date
is not a condition, you need to compare the column it with something. Presumableadmin_end_date
,
after that expression which is wrong as well.Putting it all together you get:
Unrelated, but: there is also absolutely no need to write everything in upper case.
You have a pending comma before the final parenthesis.