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 -> Performance: If...Then...Else vs Decode

Performance: If...Then...Else vs Decode

From: Alan Black <alan_at_opcomp.demon.co.uk>
Date: Wed, 23 Dec 1998 19:30:47 +0000
Message-ID: <lr1BjAAnTUg2EwHE@opcomp.demon.co.uk>


I want to decode the value of a column within an Insert Trigger to provide a description.

Setting aside any data redundancy issues...

If I want to use Decode, I have to do something like this...

        select Decode(:new.MyCode, 'C', 'Cat',
                                   'D', 'Dog',
                                   'P', Parrot',
                                   'E', 'Elephant', NULL)
        into :new.MyDescription
        from Dual;

Not only does this mean that I am making a function call, but also issuing a DML statement.

How inefficient is this, bearing mind that the code will be called many times, in comparison to the more verbose method of...

        if :new.MyCode = 'C' then

:new.MyDescription := 'Cat';
else if :new.MyCode = 'D' then
:new.MyDescription := 'Dog';
... else
:new.MyDescription := NULL;
end if;

--
Alan Received on Wed Dec 23 1998 - 13:30:47 CST

Original text of this message

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