I am new on PL SQL and I was trying to create a recursive function on it, but I am way too confused with PL SQL terms.
I have a table structure like :
FFAM_ACC_ID FFAM_UPPER_ACC_ID FFAM_GROUP_FLAG
1 0 1
2 1 1
3 1 2
4 2 1
5 4 2
6 1 2
7 6 2
8 0 1
9 8 2
Now, I would like to create a recursive function. So, if I provide a FFAM_ACC_ID
, it should be able to return me the child ids which has FFAM_GROUP_FLAG
2.
FFAM_UPPER_ACC_ID
is the parent id and FFAM_GROUP_FLAG
determines if the row is a group or not.
So, if I provide 2, it should return nothing because although it has a child row, 4. That row has FFAM_GROUP_FLAG
1. ie. it is group.
If I provide 1, it should return 3, 6, 7. This needs recursion since parent id of 3 is 1 and parent id of 7 is 6.
If I provide 9, it should return 9. Although it does not have child row, it is not a group.