Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Re: How to implement link list

Re: How to implement link list

From: John Verbil <jverbil_at_netmail.mnet.uswest.com>
Date: 1997/01/07
Message-ID: <32D2D323.748E@netmail.mnet.uswest.com>#1/1

Allen Kirby wrote:
>
> Wong Ming Ho wrote:
> >
> > Hello All,
> >
> > Does there any way to implement link list inside Oracle?
> > Thanks for advance
> >
> > :O

 <snip>

> Please note, however, that you'll have to do a query to get the next
> or previous row each time,

<snip>

Not at all, if you use START WITH and CONNECT BY.

The table used as an example could stand a bit of normalizing, so I'll start fresh, and use a forward pointer only. If Ho needs a doubly-linked list, extending this is pretty simple.

create table linked_list
(

	node_id      number not null,
	next_node_id number null

);

containing something like this:

   NODE_ID NEXT_NODE_ID
---------- ------------

         1            3
         2            4
         3            5
         4            6
         5            7
         6            8
         7            2
         8

this will select rows in linked order:

select NODE_ID from LINKED_LIST
start with NODE_ID = 1
connect by NODE_ID = prior NEXT_NODE_ID ;

   NODE_ID


         1
         3
         5
         7
         2
         4
         6
         8

START WITH and CONNECT BY are quite useful for tree-structured data as well; they can traverse up and down the branches of a tree, forward or backward, depending on how the query is coded.

-- 
John Verbil
U S WEST Communications
Information Technologies
jverbil_at_uswest.com
(303) 896-0916
Received on Tue Jan 07 1997 - 00:00:00 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US