Reputation: 688
I have this piece of code within a procedure:
if val is NULL
then
creb :=0;
else
creb := val;
end if;
Is there more elegant way to deal with null?
Upvotes: 1
Views: 98
Reputation: 52070
As a complement to Bohemian's answer, Oracle has the non-standard NVL
-- and the NVL2
if you need an else case with a value different from the condition -- functions to deal with that issue.
creb := nvl(val, 0);
COALESCE
has both advantages of being standard and accepting multiple arguments.
Upvotes: 5
Reputation: 425448
Use coalesce ()
, which returns the first non-null value in the list if values passed to it:
creb := coalesce(val, 0);
Upvotes: 6