I am working with a pl/sql procedure. I have an initialized variable myvar and I want to check its value : if it does not contain 'Z', I want it to contain 'P'.
I am currently doing it this way:
myvar := decode(myvar,'Z','Z','P');
I was just wondering if there was a simplier way to do this. I mean, decode is already simple, but I feel it's weird to specify the content of the variable while it is already in it !
If such a function would exist, it would look like this:
Function myfunction(a In Varchar2, b In Varchar2, c In Varchar2)
Return Varchar2
Is
Begin
if a <> b
then
return c;
end if;
return a;
End myfunction;
Any help would be appreciated !
There is no built-in function that does exactly what you want.
You could use CASE rather than DECODE:
CASE myvar WHEN 'Z' THEN 'Z' ELSE 'P' END
It doesn't make it any shorter though!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With