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

Home -> Community -> Usenet -> c.d.o.misc -> Re: deleting a row from a varray

Re: deleting a row from a varray

From: Jonathan Lewis <jonathan_at_jlcomp.demon.co.uk>
Date: Thu, 22 Nov 2001 14:00:07 -0000
Message-ID: <1006437477.9843.0.nnrp-13.9e984b29@news.demon.co.uk>

self.luggage.delete(i) should do what you want.

By the way, MEMBER functions had an implicit SELF parameter as the first parameter, so you may get some funny side-effects by declaring a SELF parameter explicitly.

I assume you are aware that the loop ought to be from self.luggage.first to self.luggage.last, and you may have to trap exception NO_DATA_FOUND if elements of the array are missing.

--
Jonathan Lewis
http://www.jlcomp.demon.co.uk

Host to The Co-Operative Oracle Users' FAQ
http://www.jlcomp.demon.co.uk/faq/ind_faq.html

Author of:
Practical Oracle 8i: Building Efficient Databases

Screen saver or Life saver: http://www.ud.com
Use spare CPU to assist in cancer research.

Martin Buchan wrote in message <3BF36BA5.75194F62_at_gre.ac.uk>...

>HI all,
>
>can anyone help me with this?
>What im trying to do is delete a row from the varray if certain
>conditions are met. i.e. if a player wants to eat an apple and he has
>one in his luggage array then, eat it (delete the row) and update his
>life points. Simple huh...
>
>I have a root object (player_type) with a varray (luggage_type) inside
>
>it, and a table of object type player_type. Here is a snippet of code
>from my object declaration:
>
>create or replace type player_type as object (
>p_name varchar2(25),
>life_points number(2),
>...
>luggage luggage_type_array,
>...)
>...
>MEMBER FUNCTION eatFood (self in out player_type, food varchar2) RETURN
>Number,
>PRAGMA RESTRICT_REFERENCES (eatFood, WNPS, RNPS))
>/
>heres my code for the eatFood method so far. I hope some of this makes
>sense to some of you :-)
>
>MEMBER FUNCTION eatFood (self in out player_type, food varchar2) RETURN
>number
>IS
> flag integer := 0;
> temp number := 0;
> health number(2);
> i integer;
>BEGIN
>
> for i in 1..2 loop
> if (self.luggage(i) is not null) then
> if (self.luggage(i).l_name = food) then
> health := self.luggage(i).health_bonus;
> delete from self.luggage *<<<<PROBLEM
>LINE***************
> where self.luggage(i).luggage_name = food;
> flag := 1;
> end if;
> end if;
>end loop;
>if (flag = 1) then
> self.life_points := self.life_points + health;
> return1;
>else
> return 0;
>end if;
>END;
>
>
>The error i get is:
>
>100/5 PL/SQL: SQL Statement ignored
>100/17 PLS-00201: identifier 'SELF.LUGGAGE' must be declared
>
>Anyone any ideas?
>
>thanks in advance
>
>Martin
>
>
>
Received on Thu Nov 22 2001 - 08:00:07 CST

Original text of this message

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