这是我的桌子
create table reservations (
ResID int NOT NULL,
GuestID int,
HotelID int,
Check_in DATE,
Check_out DATE,
RoomType varchar2(15),
Price Dec(8,2),
PRIMARY KEY (ResID),
CONSTRAINT FK_GuestIDX FOREIGN KEY(GuestID) REFERENCES Guests(GuestID),
CONSTRAINT FK_HotelID FOREIGN KEY(HotelID) REFERENCES Hotel(HotelID)
);
创建表没有问题。现在,我正在尝试填充表格
这是我的插入语句
insert into reservations (1, 1, 2, '17-DEC-2018', '21-DEC-2018', 'Suite', 87.03);
这是我遇到的错误
ORA-00928:缺少SELECT关键字
这可能是什么原因?
答案 0 :(得分:1)
或缺少values
:
insert into reservations
values (1, 1, 2, '17-DEC-2018', '21-DEC-2018', 'Suite', 87.03);
也就是说,我建议将其写为:
insert into reservations (ResID, GuestID, HotelID, Check_in, Check_out DATE, RoomType, Price)
values (1, 1, 2, DATE '2018-12-17', DATE '2018-12-21', 'Suite', 87.03);
注意:
insert
之后列出列。这确实可以防止难以调试的错误。DATE
关键字引入日期常数。您也可以使用SELECT
来编写此代码:
insert into reservations (ResID, GuestID, HotelID, Check_in, Check_out DATE, RoomType, Price)
select 1, 1, 2, DATE '2018-12-17', DATE '2018-12-21', 'Suite', 87.03
from dual;