Solved

Function to return yes or no

Posted on 2011-09-07
7
215 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

Suggested Solutions

Title # Comments Views Activity
JDeveloper 12c for 32 bit 4 84
Need a replacement data type in Oracle 6 77
Oracle query output question 4 43
help on oracle query 5 43
Subquery in Oracle: Sub queries are one of advance queries in oracle. Types of advance queries: •      Sub Queries •      Hierarchical Queries •      Set Operators Sub queries are know as the query called from another query or another subquery. It can …
Note: this article covers simple compression. Oracle introduced in version 11g release 2 a new feature called Advanced Compression which is not covered here. General principle of Oracle compression Oracle compression is a way of reducing the d…
This video explains what a user managed backup is and shows how to take one, providing a couple of simple example scripts.
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.

785 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