Creating a Record of some sort in PL/SQL
I'm trying to write a recursive function of sorts in PL/SQL.
The problem is:
So say table A has rows:
{B, C},
{C, D},
{C, F},
{D, E},
{E, F}
Return everything that B is dependent on, directly and indirectly.
The tuple {B, C} implies that B is dependent on C, C is dependent on D and so on and so forth. This function, when given B, would return a cursor or something that would yield: {C, D, F, E} Notice that simple looping through and just printing values may yield duplicate results (in this case, E).
I'm rather new to PL/SQL and I can't really think of a way t开发者_如何学编程o do this.
Thanks in advance for any help!
Assuming the table looks like this:
ID PARENT_ID
--- ---------
B C
C D
C F
D E
E F
Why wouldn't you use a hierarchical query like:
select distinct parent_id
from (select parent_id
from my_table
start with ID = 'B'
connect by nocycle id = prior parent_id
)
order by parent_id
This SQL's untested, but it should be a point in the right direction; your function could return that cursor if that's what you needed, or an array of values if not.
精彩评论