Search code examples
sqloracleoracle-sqldeveloper

ORA-009906: Missing left parenthesis error?


I wrote this CREATE SQL query, but when I try running it, I get this 'missing left parenthesis' error (ORA-009906), even though it doesn't look like I'm missing any, and I've been staring at the query for a whole hour trying to figure it out. I use ORACLE SQL Developer to create my queries.

CREATE TABLE new_table (driver_license  VARCHAR2(20),
                        SSN             NUMBER(10,0),
                        first_name      VARCHAR2(20),
                        last_name       VARCHAR2(20)    NOT NULL,
                        birth_date      DATE,
                        hire_date       DATE, -- The hire_date corresponds to when the employee is *first* hired.-- 
                        state           CHAR(2 BYTE)     DEFAULT 'UD',
                        CONSTRAINT ssn_pk PRIMARY KEY (SSN),
                        CHECK (hire_date > birth_date),
                        UNIQUE driver_license,
                        INDEX state_index);

Solution

  • It should be like this:

    CREATE TABLE new_table (driver_license  VARCHAR2(20),
                            SSN             NUMBER(10,0),
                            first_name      VARCHAR2(20),
                            last_name       VARCHAR2(20)    NOT NULL,
                            birth_date      DATE,
                            hire_date       DATE, -- The hire_date corresponds to when the employee is *first* hired.-- 
                            state           CHAR(2 BYTE)     DEFAULT 'UD',
                            CONSTRAINT ssn_pk PRIMARY KEY (SSN),
                            Constraint ssn_chk CHECK (hire_date > birth_date),
                            Constraint ssn_uq UNIQUE(driver_license) 
    ); 
    
    

    If you want to create also index on (state), you should use separate DDL command:

    Create index ssn_state_ix on new_table (state) ;