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

¿Hay alguna forma de seleccionar varias filas usando parámetros?

No puede devolver el conjunto de resultados en Oracle utilizando solo Query. Necesita usar el cursor Ref para lo mismo. Puede probar el siguiente código:

CREATE OR REPLACE PROCEDURE p_find_all_routes (
   p_start   IN VARCHAR2 DEFAULT '%',
   p_end     IN VARCHAR2 DEFAULT '%',
   p_via     IN VARCHAR2 DEFAULT '%',
   multiroutes OUT SYS_REFCURSOR)
AS
BEGIN
   -- =======================================================================
   -- Author:       Coilin P. Boylan Jeritslev (CTBJ)
   -- Description:   Find all possible routes between two different points
   -- "p_start" and "p_end" via the choosen point "p_via" in a graph-tabel.
   -- =======================================================================
OPEN multiroutes FOR
   WITH multiroutes (p_from, p_to, full_route, total_distance)
        AS (SELECT p_from,
                   p_to,
                   p_from || '->' || p_to full_route,
                   distance total_distance
              FROM graph
             WHERE p_from LIKE p_start
            UNION ALL
            SELECT M.p_from,
                   n.p_to,
                   M.full_route || '->' || n.p_to full_route,
                   M.total_distance + n.distance total_distance
              FROM multiroutes M JOIN graph n ON M.p_to = n.p_from
             WHERE n.p_to <> ALL (M.full_route))
     SELECT *
       FROM multiroutes
      WHERE     p_to LIKE p_end
            AND (   full_route LIKE ('%->' || p_via || '%')
                 OR full_route LIKE ('%' || p_via || '->%'))
   ORDER BY p_from, p_to, total_distance ASC;
END;
/

Luego puede llamar a este procedimiento más tarde declarando la variable de cursor Ref.

DECLARE
    Result SYS_REFCURSOR;
BEGIN
    p_find_all_routes('A','E','%', Result);
END;