这是我创建的表和我拥有的insert
语句。
这有什么问题?
CREATE TABLE FLIGHT_SA
(FLIGHT_NUMBER CHAR(10) PRIMARY KEY,
AIRCRAFT_ID CHAR(15) NOT NULL,
TRANSFER_FLIGHT_NUMBER CHAR(25) NOT NULL,
DEPARTURE_DATE_TIME TIMESTAMP,
ARRIVAL_DATE_TIME TIMESTAMP,
DEPARTURE_AIRPORT_CODE CHAR(15),
TRANSFER_AIRPORT_CODE CHAR(15),
ARRIVAL_AIRPORT_CODE CHAR(15),
DURATION CHAR(5));
INSERT INTO FLIGHT_SA
VALUES
('MS986','B773','MS798','2016-06-05 10:45:01','2016-06-05 12:45:01',
'Baltimore,MD (BWI)','Philadephia,PA (PHL)','Miami,FL (MIA)','5 HOURS');
答案 0 :(得分:3)
刚刚在sql server上尝试过,TIMESTAMP
格式在表格中必须是唯一的。我不知道你是在甲骨文。这适用于SQL服务器:
CREATE TABLE FLIGHT_SA
(FLIGHT_NUMBER CHAR(10) PRIMARY KEY,
AIRCRAFT_ID CHAR(15) NOT NULL,
TRANSFER_FLIGHT_NUMBER CHAR(25) NOT NULL,
DEPARTURE_DATE_TIME DATETIME,
ARRIVAL_DATE_TIME DATETIME,
DEPARTURE_AIRPORT_CODE CHAR(30),
TRANSFER_AIRPORT_CODE CHAR(30),
ARRIVAL_AIRPORT_CODE CHAR(30),
DURATION CHAR(10));
INSERT INTO FLIGHT_SA
VALUES
('MS986','B773','MS798','2016-06-05 10:45:01','2016-06-05 12:45:01','Baltimore,MD (BWI)','Philadephia,PA (PHL)','Miami,FL (MIA)','5 HOURS');
对于Oracle,您需要To_date
函数(http://www.techonthenet.com/oracle/questions/insert_date.php):
CREATE TABLE FLIGHT_SA
(FLIGHT_NUMBER CHAR(10) PRIMARY KEY,
AIRCRAFT_ID CHAR(15) NOT NULL,
TRANSFER_FLIGHT_NUMBER CHAR(25) NOT NULL,
DEPARTURE_DATE_TIME DATETIME,
ARRIVAL_DATE_TIME DATETIME,
DEPARTURE_AIRPORT_CODE CHAR(30),
TRANSFER_AIRPORT_CODE CHAR(30),
ARRIVAL_AIRPORT_CODE CHAR(30),
DURATION CHAR(10));
INSERT INTO FLIGHT_SA
VALUES
('MS986','B773','MS798',TO_DATE('2016-06-05 10:45:01','yyyy/mm/dd hh24:mi:ss'),TO_DATE('2016-06-05 12:45:01','yyyy/mm/dd hh24:mi:ss'),'Baltimore,MD (BWI)','Philadephia,PA (PHL)','Miami,FL (MIA)','5 HOURS');
这应该有效。我还纠正了你变量的长度。请注意,如果没有足够的空间,Oracle会截断你的字符串。