Solved

Any simpler way to avoid case

Posted on 2013-02-04
4
255 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 77

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 74

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 35

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 74

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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…
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…
This video shows syntax for various backup options while discussing how the different basic backup types work.  It explains how to take full backups, incremental level 0 backups, incremental level 1 backups in both differential and cumulative mode a…
This video shows how to Export data from an Oracle database using the Original Export Utility.  The corresponding Import utility, which works the same way is referenced, but not demonstrated.

680 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