无法在Oracle 11g数据库中插入日期

时间:2015-11-12 21:17:31

标签: sql database oracle11g

我收到了一条错误的逗号错误消息,而这似乎无法解决。我的代码如下。

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);

2 个答案:

答案 0 :(得分:4)

这对我来说有点问题:

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

尝试取消引用TO_DATE,如下所示:

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

您可能还需要先创建序列:

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);

答案 1 :(得分:1)

看起来你错过了 DOB日期后的昏迷,它应该是 DOB日期,在CREATE TABLE语句中