1
need to execute the following command on an ORACLE DB: Elaborate a select that returns more than one result and the result of this select needs to be used to make an Insert in multiple lines.
Ex: my select returned 2 results: A and B, these results should be inserted in 2 lines:
A
B
How can I do that? Follows 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 running Insert/update it inserts only 1 result on all lines.
posted the code I made based on your example. It makes the select of 3 information, but adds only one on all lines.
– Fernando Kowacic