Solved

Function to return yes or no

Posted on 2011-09-07
7
214 Views
Last Modified: 2012-06-27
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';

0
Comment
Question by:Swadhin Ray
  • 4
  • 3
7 Comments
 
LVL 28

Expert Comment

by:Naveen Kumar
ID: 36494383
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;
/
0
 
LVL 16

Author Comment

by:Swadhin Ray
ID: 36494388
What are the other ways we can do it ?

0
 
LVL 16

Author Comment

by:Swadhin Ray
ID: 36494389
the one you gave I have already done it but still want to know any other method ..
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 28

Expert Comment

by:Naveen Kumar
ID: 36494406
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


0
 
LVL 28

Expert Comment

by:Naveen Kumar
ID: 36494414
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.
0
 
LVL 28

Accepted Solution

by:
Naveen Kumar earned 500 total points
ID: 36494447
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;

0
 
LVL 16

Author Closing Comment

by:Swadhin Ray
ID: 36494567
Thanks
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction A previously published article on Experts Exchange ("Joins in Oracle", http://www.experts-exchange.com/Database/Oracle/A_8249-Joins-in-Oracle.html) makes a statement about "Oracle proprietary" joins and mixes the join syntax with gen…
How to Create User-Defined Aggregates in Oracle Before we begin creating these things, what are user-defined aggregates?  They are a feature introduced in Oracle 9i that allows a developer to create his or her own functions like "SUM", "AVG", and…
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database
This video shows how to copy a database user from one database to another user DBMS_METADATA.  It also shows how to copy a user's permissions and discusses password hash differences between Oracle 10g and 11g.

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now