Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Function to return yes or no

Posted on 2011-09-07
7
Medium Priority
?
226 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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 2000 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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

Have you ever had to make fundamental changes to a table in Oracle, but haven't been able to get any downtime?  I'm talking things like: * Dropping columns * Shrinking allocated space * Removing chained blocks and restoring the PCTFREE * Re-or…
Cursors in Oracle: A cursor is used to process individual rows returned by database system for a query. In oracle every SQL statement executed by the oracle server has a private area. This area contains information about the SQL statement and the…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
This video shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…

618 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