В моем коде я пытаюсь вставить данные в цикл for на основе номера строки. Причина, по которой я хочу использовать его, заключается в том, что в противном случае я получаю ошибку «однострочный подзапрос возвращает более одной строки», потому что мои подзапросы select возвращают более одной строки, и я, очевидно, хочу вставить ее по одному.Вставить строки с помощью ROWNUM В Oracle
declare
begin
for x in (select * from PilotKeyLookup) loop
if x.p2id != null then
insert into BridgeTable (groupid, pilotid) values (sqBridgeGroupID.nextval, (select p1id from PilotKeyLookup));
insert into BridgeTable (groupid, pilotid) values (sqBridgeGroupID.currval, (select p2id from PilotKeyLookup));
else
insert into BridgeTable (groupid, pilotid) values (sqBridgeGroupID.nextval, (select p1id from PilotKeyLookup));
end if;
end loop;
end;
И это, как я пытаюсь использовать ROWNUM:
declare
begin
for x in (select * from PilotKeyLookup) loop
if x.p2id != null then
insert into BridgeTable (groupid, pilotid) values (sqBridgeGroupID.nextval, (select p1id from PilotKeyLookup where rownum = x));
insert into BridgeTable (groupid, pilotid) values (sqBridgeGroupID.currval, (select p2id from PilotKeyLookup where rownum = x));
else
insert into BridgeTable (groupid, pilotid) values (sqBridgeGroupID.nextval, (select p1id from PilotKeyLookup where rownum = x));
end if;
end loop;
end;
Однако, я получаю «выражение неправильного типа» ошибка. Любые предложения?
Это приятное решение! –
Спасибо, он работал как шарм. Я решил выбрать это решение, потому что он работал быстрее, чем тот, который приведен ниже. – Istvan