Jacob Ricci
Jacob Ricci

Reputation: 171

Trouble inserting dates into Oracle 11g Database

I'm getting a missing comma error message which I can't seem to fix. My code is below.

CREATE TABLE Customers
(
C_Id int NOT NULL PRIMARY KEY,
DOB date
Age int,
FirstName varchar(255),
LastName varchar(255),
City varchar(255),
MemberSince int
);

INSERT 
INTO
   Customers

VALUES
  (C_Id.nextval,'TO_DATE( '02-DEC-1977', 'DD-MON-YYYY' )',37,'Joseph','Smith','Minneapolis',2004);

Upvotes: 1

Views: 49

Answers (2)

Didier A.
Didier A.

Reputation: 4816

This looks problematic to me:

'TO_DATE( '02-DEC-1977', 'DD-MON-YYYY' )'

Try unquoting the TO_DATE like this:

TO_DATE( '02-DEC-1977', 'DD-MON-YYYY' )

You might also need to create the sequence first:

CREATE SEQUENCE C_Id
  MINVALUE 1
  MAXVALUE 999999999999999999999999999
  START WITH 1
  INCREMENT BY 1
 CACHE 20;

CREATE TABLE Customers
(
  C_Id int NOT NULL PRIMARY KEY,
  DOB date,
  Age int,
  FirstName varchar(255),
  LastName varchar(255),
  City varchar(255),
  MemberSince int
);

INSERT 
INTO
  Customers
VALUES
  (C_Id.nextval,TO_DATE( '02-DEC-1977', 'DD-MON-YYYY' ),37,'Joseph','Smith','Minneapolis',2004);

Upvotes: 4

Sergiu Velescu
Sergiu Velescu

Reputation: 514

looks like you missed the coma after DOB date it should be DOB date, in CREATE TABLE statement

Upvotes: 1

Related Questions