Solved

Function to return yes or no

Posted on 2011-09-07
7
220 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Working with Network Access Control Lists in Oracle 11g (part 2) Part 1: http://www.e-e.com/A_8429.html Previously, I introduced the basics of network ACL's including how to create, delete and modify entries to allow and deny access.  For many…
Configuring and using Oracle Database Gateway for ODBC Introduction First, a brief summary of what a Database Gateway is.  A Gateway is a set of driver agents and configurations that allow an Oracle database to communicate with other platforms…
This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.

688 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