Solved

Any simpler way to avoid case

Posted on 2013-02-04
4
249 Views
Last Modified: 2013-02-07
select case when d.arn_no is not null then to_char(d.arn_no)
                                                                     when d.boe_no is not null then d.boe_no
                                                                     else d.do_no end
from docs d

Is there any other simpler way without using case.?
0
Comment
Question by:sakthikumar
  • 2
4 Comments
 
LVL 76

Assisted Solution

by:slightwv (䄆 Netminder)
slightwv (䄆 Netminder) earned 125 total points
ID: 38850950
Looks like you are looking to find the first not null in a list of values.

If so, try coalesce:

coalesce(d.arn_no ,d.boe_no, d.do_no)
0
 
LVL 73

Assisted Solution

by:sdstuber
sdstuber earned 250 total points
ID: 38850955
case seems like the simplest way but if you don't want to use it, you could try nvl2 and nvl

select nvl2(d.arn_no,nvl(d.boe_no,d.do_no),to_char(d.arn_no)) from docs d
0
 
LVL 34

Assisted Solution

by:johnsone
johnsone earned 125 total points
ID: 38850957
I believe that this will do the same thing:

nvl2(d.arn_no, to_char(d.arn_no), nvl2(d.boe_no, d.boe_no, d.do_no))
0
 
LVL 73

Accepted Solution

by:
sdstuber earned 250 total points
ID: 38850965
if you want to use coalesce, then all of the parameters must be of the compatible types.
i.e.  all numbers or all strings

based on your original code, it seems like arn_no is a number and the others are strings.
if so then try this...

coalesce(to_char(d.arn_no) ,d.boe_no, d.do_no)
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.

Join & Write a Comment

Suggested Solutions

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…
From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
This video shows setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines
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.

757 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

27 Experts available now in Live!

Get 1:1 Help Now