Non è possibile restituire il set di risultati in Oracle utilizzando solo Query. È necessario utilizzare il cursore Ref per lo stesso. Puoi provare sotto il codice -
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;
/
È quindi possibile richiamare questa procedura in un secondo momento dichiarando la variabile del cursore Ref.
DECLARE
Result SYS_REFCURSOR;
BEGIN
p_find_all_routes('A','E','%', Result);
END;