有人可以告诉我这个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’);
答案 0 :(得分:1)
您在第一个参数周围缺少单引号。我会建议其他三个变化:
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中删除主键