将日期类型值插入Oracle中的表:ORA-00984

时间:2018-01-10 16:33:24

标签: sql oracle

我根据下图创建了两个表:

diagram

我现在正在尝试使用测试数据填充这些表,并且我无法在PositionLogEntry表中插入日期类型列而收到错误:PL / SQL:ORA-00984:此处不允许列。

declare

noOfFlights constant int:= 10; noOfLog constant int:=100;

begin

for m in 1..noOfFlights loop

insert into Flight (aircraftRegistration, DateAndTimeDeparture,pilotInCommand) values ( 'Aircraft Registration' || to_char(sqFlight.nextval), to_date('2000-01-01 00:00:00', 'YYYY-MM-DD hh24:mi:ss') + to_ymInterval(to_char(floor(dbms_random.value(1,30))) || '-' || to_char(floor(dbms_random.value(1,12)))), 'Pilot in Command' || to_char(sqFlight.currval)); end loop;

for c in 1..noOfLog loop for m in (select AIRCRAFTREGISTRATION, DATEANDTIMEDEPARTURE from Flight) loop

insert into POSITIONLOGENTRY (AIRCRAFTREGISTRATION, DATEANDTIMEDEPARTURE, logTime, positionLatitude, positionLongtitude, courseDegrees, headingDegree, horizontalSpeedKnots, verticalSpeedKnots, altitudeFeet, altitudeFlightLevels) values ( AIRCRAFTREGISTRATION, DATEANDTIMEDEPARTURE, to_date('2000-01-01 00:00:00', 'YYYY-MM-DD hh24:mi:ss') + to_ymInterval(to_char(floor(dbms_random.value(1,30))) || '-' || to_char(floor(dbms_random.value(1,12)))), round(dbms_random.value(7,0)), round(dbms_random.value(7,0)), round(dbms_random.value(3,0)), round(dbms_random.value(3,0)), round(dbms_random.value(3,0)), round(dbms_random.value(3,0)), round(dbms_random.value(4,0)), round(dbms_random.value(4,0))); end loop;

end loop;

/commit;/

end; /

P.S。 Flight表格正确填充。 你能否提出任何可能的解决方案? 谢谢!

1 个答案:

答案 0 :(得分:2)

您不能在AIRCRAFTREGISTRATION, DATEANDTIMEDEPARTURE子句中使用列名VALUES等。

使用

m.AIRCRAFTREGISTRATION,
m.DATEANDTIMEDEPARTURE

代替。