dbTalk Databases Forums  

Recursive fetch

comp.database.oracle comp.database.oracle


Discuss Recursive fetch in the comp.database.oracle forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
wish
 
Posts: n/a

Default Recursive fetch - 10-12-2006 , 11:51 AM






Hi, I'm trying to produce a stored procedure or function which would allow
me to fetch tree data stored in a table.

Records of this table looks like:
Id | ParentId | Value1 | Value2....

What I want to do is to fetch some rows starting from an Id number and using
this number as ParentId to get child rows recursively to produce single list
of rows. Is there is a way to join (union) cursors taken from subsequent
function calls to fetch their records somehow? I was also thinking about
using temporary table but if there's a simpler way, please let me know .

Thanks,
wish



Reply With Quote
  #2  
Old   
KM
 
Posts: n/a

Default Re: Recursive fetch - 10-15-2006 , 10:00 AM






Quote:
Hi, I'm trying to produce a stored procedure or function which would allow
me to fetch tree data stored in a table.

Records of this table looks like:
Id | ParentId | Value1 | Value2....

What I want to do is to fetch some rows starting from an Id number and
using this number as ParentId to get child rows recursively to produce
single list of rows.
Hi,

I think there is no need to use pl/sql to select such kind of data. Oracle
has the 'start with ... connect by' clause that can be used to select
hierarchical data. Here you have an example of usage in
http://www.adp-gmbh.ch/ora/sql/connect_by.html

So, you can use a simple query in SQL:

select
level,
id,
parentid,
value1,
value2
from
yourtable
start with
parentid is null /* root */
connect by prior
id = parentid;


--
KM






Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.