Search code examples
sqloracle-databasesqlpluscreate-table

SQL Error: Missing Right Parenthesis in Line 1 ORA-00907


I've checked other similar questions. about repeating commas, error in commands but cant find any in my error. I've also searched examples of create tables to compare with mine, but fail to find any difference :(.

Below is the CREATE table statement:

CREATE TABLE DRIVER(L# VARCHAR(15) NOT NULL
                       , DNAME VARCHAR(75) NOT NULL
                       , STATUS  VARCHAR(50) NOT NULL
                       , NRIC VARCHAR (15) NOT NULL
                       , PRIMARY KEY(L#)
                       , CANDIDATE KEY(NRIC)
      );

Anyone can help me point out that i can't see or missing something,thanks (:


Solution

  • You can't specify CANDIDATE KEY like that in Oracle. The right way is to create a UNIQUE CONSTRAINT on your Candidate Key(s).

    Like so.

    Here's a working SQLFiddle: http://sqlfiddle.com/#!4/b392d/1

    CREATE TABLE DRIVER(
        L# VARCHAR(15) NOT NULL, 
        DNAME VARCHAR(75) NOT NULL, 
        STATUS VARCHAR(50) NOT NULL, 
        NRIC VARCHAR (15) NOT NULL, 
      PRIMARY KEY(L#),
        CONSTRAINT UK_NRIC UNIQUE (NRIC)
    );