Du kan ikke returnere resultatsættet i Oracle ved kun at bruge Query. Du skal bruge Ref cursor til det samme. Du kan prøve nedenstående kode -
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;
/
Du kan derefter kalde denne procedure senere ved at erklære Ref cursor variabel.
DECLARE
Result SYS_REFCURSOR;
BEGIN
p_find_all_routes('A','E','%', Result);
END;