vilezz
vilezz

Reputation: 3

Getting "missing right parenthesis' error SQL--Cannot find the issue

I am trying to create four tables below. My first two tables run correctly, but my last two error out with the same error message:

ORA-00907: missing right parenthesis
ORA-06512: at "SYS.WWV_DBMS_SQL_APEX_200200", line 626
ORA-06512: at "SYS.DBMS_SYS_SQL", line 1658
ORA-06512: at "SYS.WWV_DBMS_SQL_APEX_200200", line 612
ORA-06512: at "APEX_200200.WWV_FLOW_DYNAMIC_EXEC", line 1749

I cannot figure out what is wrong with this code. I recognize that it's probably a syntax error somewhere, but I cannot find it. What should I do to fix this error?

create table item 
(
     itemID number(5) constraint CAMP_itemID_pk primary key, 
     itemDescription varchar2(100), 
     cleaned varchar2(1), 
     stock number(5)
);

create table people 
(
    peopleID number(10) constraint CAMP_peopleID_pk primary key, 
    firstName varchar2(20), 
    lastName varchar2(20), 
    phone number(10), 
    discount varchar2(20)
);

create table checkout 
(
    checkoutID constraint CAMP_checkoutID_pk primary key number(10), 
    peopleID number(10), 
    checkoutDate date(), 
    returnDate date(), 
    saleTotal number(10), 
    returned varchar(1), 
    constraint CAMP_peopleID_fk foreign key (peopleID) references people(peopleID)
);

create table checkoutDetail 
(
    orderDetailID constraint CAMP_orderDetailID_pk primary key number(10), 
    checkoutID number(10), 
    itemID,  
    quantity number(5), 
    constraint CAMP_checkoutID_fk foreign key (checkoutID) references checkout(checkoutID), 
    constraint CAMP_itemID_fk foreign key (itemID) references item(itemID)
);

Upvotes: 0

Views: 521

Answers (1)

MT0
MT0

Reputation: 167822

  1. The syntax is to define a column with inline constraints is:

    COLUMN_NAME DATATYPE CONTRAINTS
    

    but you have the data type after the constraints.

  2. Date has no precision (and is not a function) so should not have braces after it.

  3. itemID needs a data type.

Like this:

create table checkout (
  checkoutID   number(10) constraint CAMP_checkoutID_pk primary key,
  peopleID     number(10),
  checkoutDate date,
  returnDate   date,
  saleTotal    number(10),
  returned     varchar(1), 
  constraint CAMP_peopleID_fk foreign key (peopleID) references people(peopleID)
);

create table checkoutDetail (
  orderDetailID number(10) constraint CAMP_orderDetailID_pk primary key,
  checkoutID    number(10),
  itemID        number(5),
  quantity      number(5), 
  constraint CAMP_checkoutID_fk foreign key (checkoutID) references checkout(checkoutID),
  constraint CAMP_itemID_fk foreign key (itemID) references item(itemID)
);

db<>fiddle here

Upvotes: 2

Related Questions