Oracle SQL语句不起作用

时间:2017-04-07 11:07:19

标签: sql oracle

有人可以告诉我这个SQL究竟出了什么问题,以及为什么它没有执行!

DROP TABLE CAR5849;
CREATE TABLE CAR5849 (
  IDNO      VARCHAR(20) PRIMARY KEY
, MAKE        VARCHAR(20)
, MILES      NUMBER(6)
, DATEOFPURCHASE      DATE
);


INSERT INTO CAR5849 (IDNO, MAKE, MILES, DATEOFPURCHASE) VALUES (PGJ058,'Red Mustang', 27070, TO_DATE(‘11/07/2011’, ‘DD/MM/YYYY’);
INSERT INTO CAR5849 (IDNO, MAKE, MILES, DATEOFPURCHASE) VALUES (PGJ058,'Yellow Mustang', 35725, TO_DATE(‘24/09/2015’, ‘DD/MM/YYYY’);
INSERT INTO CAR5849 (IDNO, MAKE, MILES, DATEOFPURCHASE) VALUES (PGJ058,'Black Mustang', 14589, TO_DATE(‘11/02/2010’, ‘DD/MM/YYYY’);

2 个答案:

答案 0 :(得分:1)

您在第一个参数周围缺少单引号。我会建议其他三个变化:

  • VARCHAR2而不是VARCHAR
  • DATE代替TO_DATE()
  • IDNO删除主键,因为您似乎想要将列设置为多行中的相同值。

所以:

DROP TABLE CAR5849;

CREATE TABLE CAR5849 (
  IDNO      VARCHAR2(20),
  MAKE      VARCHAR2(20),
  MILES      NUMBER(6),
  DATEOFPURCHASE  DATE
);

INSERT INTO CAR5849 (IDNO, MAKE, MILES, DATEOFPURCHASE)
    VALUES ('PGJ058', 'Red Mustang', 27070, DATE '2011-07-11');
INSERT INTO CAR5849 (IDNO, MAKE, MILES, DATEOFPURCHASE)
    VALUES ('PGJ058', 'Yellow Mustang', 35725, DATE '2015-09-24');
INSERT INTO CAR5849 (IDNO, MAKE, MILES, DATEOFPURCHASE)
    VALUES ('PGJ058', 'Black Mustang', 14589, DATE '2010-02-11');

答案 1 :(得分:0)

列IDNO被定义为主键,因此您无法为此列添加重复条目,所有3个插入语句具有相同的IDNO值,具有IDNO的唯一值或从IDNO中删除主键