I need to run the following command in an ORACLE DB: Elaborate a select that returns more than one result and the result of this select need to use to make an insert in several lines.
Ex: My select returned 2 results: A and B, these results should be entered in 2 lines:
A
B
How can I do this? Here is an elaborate code:
DECLARE
cursor insere is
select campo_valor_tarefa.ds_valor from campo_valor_tarefa
inner join fluxo
on campo_valor_tarefa.cd_fluxo = fluxo.cd_fluxo
where campo_valor_tarefa.cd_tarefa = 2 and campo_valor_tarefa.cd_campo = 10 and fluxo.cd_processo = 180 and campo_valor_tarefa.cd_fluxo <344;
linha insere%rowtype;
BEGIN
OPEN insere;
loop
FETCH insere into linha;
exit when insere%notfound;
UPDATE campo_valor_tarefa set ds_valor = (
SELECT ds_valor FROM CAMPO_VALOR_TAREFA WHERE cd_campo = 10 AND cd_tarefa=2 AND cd_fluxo = 341
)
where cd_campo = 126 and cd_tarefa = 6 and cd_fluxo = 344;
end loop;
close insere;
end;
If I run select at the beginning of the code it returns 2 results and at the time of executing insert / update it inserts only 1 result on all lines.