Re: pl/sql: test if record is empty

From: Vince <vinnyop_at_yahoo.com>
Date: Thu, 29 May 2008 16:16:16 -0700 (PDT)
Message-ID: <9eb4e3a1-68bd-40e0-862a-82ae5aa67584@p39g2000prm.googlegroups.com>


On May 29, 11:28 am, Donkey Hot <s..._at_plc.is-a-geek.com> wrote:
> steph <stepha..._at_yahoo.de> wrote innews:76d293f6-0d3f-4968-94a7-9e18613a2339_at_s50g2000hsb.googlegroups.com:
>
>
>
>
>
> >> > Similarily, how can I empty a record? Do I need to empy all of it's
> >> > components like:
>
> >> > declare
> >> >   o_rec mytab%ROWTYPE;
> >> > begin
> >> >   o_rec.empno:=null;
> >> >   o_rec.empname:=null;
> >> >   ...
> >> > end;
>
> >> > cheers,- Hide quoted text -
>
> >> > - Show quoted text -
>
> >> Steph,
> >> Just set the ROWTYPE variable to null:
> >> o_rec := NULL;
>
> >> Regards,
> >> Vince
>
> > you're right. of courese this works. silly me ...
> > thanks
>
> Really?
>
> What happens with code?
>
>         declare
>           o_rec mytab%ROWTYPE;
>         begin
>           o_rec := null ;
>           o_rec.empno:=null;            -- null pointer exception?
>           o_rec.empname:=null;
>           ...
>         end;
>
> If the o_rec "points" to null, how can it's attributes be accessed? I guess
> they can not.- Hide quoted text -
>
> - Show quoted text -

Simple test shows there is no problem:

create table mytab (tab_id integer, tab_name varchar2(100));

DECLARE     o_rec mytab%ROWTYPE;

BEGIN     o_rec.tab_id := 1;
    o_rec.tab_name := 'FooBar';

    dbms_output.put_line( 'tab_id=' || o_rec.tab_id || ', tab_name=' || o_rec.tab_name );

    o_rec := NULL;

    dbms_output.put_line( 'tab_id=' || o_rec.tab_id || ', tab_name=' || o_rec.tab_name );

END; the results without an exception raised:

tab_id=1, tab_name=FooBar
tab_id=, tab_name= Received on Thu May 29 2008 - 18:16:16 CDT

Original text of this message