sql >> Database >  >> RDS >> Oracle

Is er een manier om meerdere rijen te selecteren met behulp van parameters?

U kunt de resultatenset in Oracle niet retourneren door alleen Query te gebruiken. U moet hiervoor de Ref-cursor gebruiken. Je kunt onderstaande code proberen -

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;
/

U kunt deze procedure later oproepen door Ref cursor variabele te declareren.

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




  1. query in codeigniter:krijg waar of

  2. Is er een booleaans type in Oracle-databases?

  3. PHP Controleer of string een letter bevat

  4. Hoe GROUP BY record verder filteren in mysql?