Search code examples
sqloraclecomputer-scienceinformation-schema

How do I solve the Missing Paranthesis error


I'm trying to a create table command to create a relation;

create table Driver(

Driver_Licence char(15) primary key,

SSN int unique,

First_Name varchar(50) not null,

Last_Name varchar(50),

Birth_Date date DEFAULT '1900-01-01',

Hire_Date date COMMENT 'Hire_Date is the date that employee was first Hired',

State char(2),

INDEX (State),

CONSTRAINT CHK_Driver_HireDate CHECK(Hire_Date > Birth_Date)

);

But I keep getting this error:

Error report -
ORA-00907: missing right parenthesis
00907. 00000 -  "missing right parenthesis"
*Cause:    
*Action:

I've been trying to figure it out, but I've been having trouble figuring out how to solve it. It would be a great help if one of you could help me!


Solution

  • I don't think Oracle supports either inline comments in tables or the creation of indexes. These need to be separate statements.

    Oracle recommends using varchar2() instead of varchar(). And the date literal should be preceded with date:

    create table Driver(
        Driver_Licence char(15) primary key,
        SSN int unique,
        First_Name varchar2(50) not null,
        Last_Name varchar2(50),
        Birth_Date date DEFAULT date '1900-01-01',
        Hire_Date date,
        State char(2),
        CONSTRAINT CHK_Driver_HireDate CHECK(Hire_Date > Birth_Date)
    );
    
    comment on column driver.hire_date is 'Hire_Date is the date that employee was first Hired';
    
    create index idx_driver_state on driver(state);
    

    Here is a db<>fiddle.