Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1057813
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T17:55:42+00:00 2026-05-16T17:55:42+00:00

In my Oracle database, I have a table called Customers. There are fields for

  • 0

In my Oracle database, I have a table called Customers. There are fields for name, zip, city etc., but there are also fields for invoicename, invoicezip and invoicecity. For some records the invoicespecific fields are not set, and in that case the invoice method should use the information from name, zip and city.

I use the following query now:

select
  case when c.InvoiceName is null then c.Name else c.InvoiceName end as Name,
  case when c.InvoiceName is null then c.Zip  else c.InvoiceZip  end as Zip,
  case when c.InvoiceName is null then c.City else c.InvoiceCity end as City  
  <...>
from
  Customers c
where
  Accountnumber=:accountnumber

Note that the check is on InvoiceName only. If that value is set I want to return all the invoice-specific fields, if not I want to return all the “non-invoice-specific” fields.

What I would like to do is something like this

select
  case when c.InvoiceName is not null
    then 
      c.InvoiceName as Name, 
      c.InvoiceZip as Zip, 
      c.InvoiceCity as City
      <...>
    else 
      c.Name, 
      c.Zip, 
      c.City
      <...>
  end
from
  customers c

Is there way to do this or something like it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T17:55:43+00:00Added an answer on May 16, 2026 at 5:55 pm

    A CASE expression can only return one value, not 3, so you do need the 3 CASE expressions. Using DECODE would be slightly more concise, but DECODE is Oracle-specific whereas CASE is ANSI standard and so preferable. But for info it would look like:

    select
      decode(c.InvoiceName,null,c.Name,c.InvoiceName) as Name,
      decode(c.InvoiceName,null,c.Zip,c.InvoiceZip) as Zip,
      decode(c.InvoiceName,null,c.City,c.InvoiceCity) as City  
      <...>
    from
      Customers c
    where
      Accountnumber=:accountnumber
    

    Another rarely-used but very applicable Oracle-specific function is NVL2:

    select
      nvl2(c.InvoiceName,c.InvoiceName,c.Name) as Name,
      nvl2(c.InvoiceName,c.InvoiceZip,c.Zip) as Zip,
      nvl2(c.InvoiceName,c.InvoiceCity,c.City) as City  
      <...>
    from
      Customers c
    where
      Accountnumber=:accountnumber
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table, users, in an Oracle 9.2.0.6 database. Two of the fields
In our Oracle database we have a table called RULES, with a field called
In my oracle database I have table called PERSON with columns code, surname, forename.
Given: Oracle 10.2g is the database I have a table called emp. emp has
I have a oracle table called: create table InsertHere( generate_id varchar2(10), name varchar2(100) );
I have a table in an oracle database with 15 fields. This table had
I have an Oracle database and the boolean fields are CHAR(1) with Y/N stored.
I have a Oracle database and one of the fields is a date range
I would like to have a table in my Oracle database whose rows act
I have rows in an Oracle database table which should be unique for a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.