sql >> Base de Datos >  >> RDS >> Oracle

¿Cómo devolver varias filas del procedimiento almacenado de Oracle desde varios cursores?

Mi sugerencia será insertar las filas de su cursor en una tabla temporal. Luego, una la tabla temporal con su tabla existente para los criterios de filtro que menciona. Psuedocódigo:

create or replace function my_func
return sysrefcursor
is
    cursor cursor_one is 
        SELECT * FROM table_one ; 

    cursor cursor_two is 
        SELECT * FROM table_one ; 
    BEGIN    

     FOR current_row in cursor_one
      loop 

          -- do some modification on each row and insert into temporary table

      end loop; 



     FOR current_row in cursor_two
      loop 

          -- do some modification on each row and insert into temporary table

      end loop; 


    -- results from cursor 1 and 2 exist in temporary table

    open out_cursor for
     select t.* from
      my_temp_table t
      join
      my_other_table tt
      on (t.col1 = tt.col1) -- or whatever columns are appropriate
      where t.col2 = 'some criteria' -- or whatever filter criteria you like.

    return out_cursor;

    END;