Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.misc -> Performance: If...Then...Else vs Decode
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