Solved

Any simpler way to avoid case

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Oracle Pivot 2 43
Migrating an SQL 2008 database to Oracle 12c 3 89
Wrap Oraccle SQL*Plus executable Command 4 69
Oracle Pivot Question 8 45
This article started out as an Experts-Exchange question, which then grew into a quick tip to go along with an IOUG presentation for the Collaborate confernce and then later grew again into a full blown article with expanded functionality and legacy…
How to Unravel a Tricky Query Introduction If you browse through the Oracle zones or any of the other database-related zones you'll come across some complicated solutions and sometimes you'll just have to wonder how anyone came up with them.  …
This video shows how to copy a database user from one database to another user DBMS_METADATA.  It also shows how to copy a user's permissions and discusses password hash differences between Oracle 10g and 11g.
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.

920 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

15 Experts available now in Live!

Get 1:1 Help Now