WITH Ancestor(arg1, arg2) AS
(
SELECT p.arg1, p.arg2
FROM parent p
WHERE arg2 NOT IN
(
SELECT arg1
FROM parent
)
UNION ALL
SELECT p.arg1, a.arg2
FROM Ancestor a
JOIN parent p
ON p.arg2 = a.arg1
)
SELECT *
FROM Ancestor
Oracle
केवल पुनरावर्ती CTE
का समर्थन करता है चूंकि 11g
रिलीज 2.
पुराने संस्करणों में, CONNECT BY
. का उपयोग करें खंड:
SELECT arg1, CONNECT_BY_ROOT arg2
FROM parent
START WITH
arg2 NOT IN
(
SELECT arg1
FROM parent
)
CONNECT BY
arg2 = PRIOR arg1