Function to return yes or no

Swadhin Ray
Swadhin Ray used Ask the Experts™
on
Hello Experts,

I want to create a function which will return me "YES" or "NO"

The input to the function can be varchar2 ...
So if the input values if not null then return "YES"
else if the input is null then return "NO';

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Naveen KumarProduction Manager / Application Support Manager

Commented:
it can be done in many ways.. one way is given below :

create function f1 ( input varchar2) return varchar2 is
begin
if input is not null then
return 'YES';
else return 'NO'
end if;
end;
/
What are the other ways we can do it ?

the one you gave I have already done it but still want to know any other method ..
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Naveen KumarProduction Manager / Application Support Manager

Commented:
typo in my previous post. use this. this works for me.

create or replace function f1 ( input varchar2) return varchar2 is
begin
if ( input is not null )
then
return 'YES';
else return 'NO';
end if;
end;
/

to test it :

select f1('testing') results from dual; -- returns YES

select f1('') results from dual;  -- returns NO


Naveen KumarProduction Manager / Application Support Manager

Commented:
what i meant was we can use CASE or DECODE or NVL etc instead of IF clause in the function code. It does not really matter much to mention but yes we can use any of the above functions/constructs to get this function done.
Production Manager / Application Support Manager
Commented:
just another method....

create or replace function f1 ( input varchar2) return varchar2 is
begin
return case when input is null then 'NO' else 'YES' end;
end;
/


select f1('testing') results from dual;

select f1('') results from dual;

Thanks

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial