dbTalk Databases Forums  

Substituting NVL2() with CASE

comp.database.oracle.misc comp.database.oracle.misc


Discuss Substituting NVL2() with CASE in the comp.database.oracle.misc forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Sean Nakasone
 
Posts: n/a

Default Substituting NVL2() with CASE - 09-18-2007 , 07:28 PM






I'm looking for an NVL2() substitute. Someone has suggested using case,
but I've always seen case in scripts, not in a single statement. For
example, NVL2() can be used in a single SQL statement like:

SELECT g3e_fid, hs_prefix, hs_number, hs_suffix,
NVL2 (hs_prefix,
hs_prefix || '-' || hs_number || hs_suffix,
hs_number || hs_suffix
) addr_number
FROM parcel_labels_o1

Anyone have an example of using case in a single statement?


Reply With Quote
  #2  
Old   
David Portas
 
Posts: n/a

Default Re: Substituting NVL2() with CASE - 12-21-2007 , 12:01 PM






"Sean Nakasone" <seannakasone (AT) yahoo (DOT) com> wrote

Quote:
I'm looking for an NVL2() substitute. Someone has suggested using case,
but I've always seen case in scripts, not in a single statement. For
example, NVL2() can be used in a single SQL statement like:

SELECT g3e_fid, hs_prefix, hs_number, hs_suffix,
NVL2 (hs_prefix,
hs_prefix || '-' || hs_number || hs_suffix,
hs_number || hs_suffix
) addr_number
FROM parcel_labels_o1

Anyone have an example of using case in a single statement?

How about using COALESCE:

SELECT g3e_fid, hs_prefix, hs_number, hs_suffix,
COALESCE (hs_prefix || '-' || hs_number || hs_suffix,
hs_number || hs_suffix
) addr_number
FROM parcel_labels_o1;

The CASE version would be:

SELECT g3e_fid, hs_prefix, hs_number, hs_suffix,
CASE WHEN hs_prefix IS NOT NULL
THEN hs_prefix || '-' || hs_number || hs_suffix
ELSE hs_number || hs_suffix
END addr_number
FROM parcel_labels_o1;

Both versions are ANSI/ISO SQL.

--
David Portas




Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.