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

Home -> Community -> Usenet -> c.d.o.tools -> Re: Linked Lists in PL/SQL

Re: Linked Lists in PL/SQL

From: Reinier <Reinier_Dickhout_at_hetnet.nl>
Date: Thu, 14 Sep 2000 10:06:47 +0200
Message-ID: <e3GvaLiHAHA.225@net025s>

There are two things you need to consider. First design your tables the right way, for example:

create table linked_list (
id number(10) not null,
prev_id number(10),
next_id number(10),
);

create table ll_values (
id number(10) not null,
ll_value varchar2(255)
)

Second, you need your pre-insert, pre-update and pre-delete triggers to function properly, for example

create or replace trigger app_llv_brd
before delete on ll_values
for each row
begin
  update linked_list a
  set a.next_id =
   (select b.next_id
    from linked_list b
   where b.id = a.next_id)
  where a.next_id = :old.id;
  update linked_list a
  set a.prev_id =
   (select b.prev_id
    from linked_list b
   where b.id = a.prev_id)
  where a.prev_id = :old.id;
  delete from linked_list
  where id = :old.id;
end app_llt_bru;

now you have two table, one holding the actual values (ll_values) and one implementing the linked list functionality. This way you can update the linked list when you delete a row without having to deal with the mutating table error.

You still have some work to do on the other triggers though.

Reinier.

Clix <Helder.Biscaia_at_clix.pt> wrote in message news:968890531.763940_at_cachalote.ip.pt...
> Is it possible to create linked lists in PL/SQL? If so, would someone
> please point me in the right direction (ie. what and where can I find
 info
> on this). Of couse, sample code snips are always welcomed :-)
>
> thanks a million.
>
>
Received on Thu Sep 14 2000 - 03:06:47 CDT

Original text of this message

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