© Kim Berg Hansen 2020
K. Berg HansenPractical Oracle SQLhttps://doi.org/10.1007/978-1-4842-5617-6_4

4. Tree Calculations with Recursion

Kim Berg Hansen1 
(1)
Middelfart, Denmark
 

Any procedural language I can think of supports some form of recursion. A procedure or function can call itself – if needed repeatedly until some condition has been reached. Typically they’ll also support iteration, which is related but not quite the same.

SQL deals with sets of rows, not procedural logic, so how can you do recursion in SQL? It still concerns itself with sets of rows: first find a set of rows; then based on that set of rows, you apply some logic to find a second set of rows; then based on that set of rows, you apply the logic again (recursively) to find a ...

Get Practical Oracle SQL: Mastering the Full Power of Oracle Database now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.