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

  • Home
  • SEARCH
  • 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 8932339
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:18:20+00:00 2026-06-15T09:18:20+00:00

It seems like the simple CASE expression and the DECODE function are equivalent and

  • 0

It seems like the simple CASE expression and the DECODE function are equivalent and that the results returned by them should be identical. Are they?

The documentation has the following to say about the simple CASE expression:

The simple CASE expression returns the first result for which
selector_value matches selector. Remaining expressions are not
evaluated. If no selector_value matches selector, the CASE expression
returns else_result if it exists and NULL otherwise.

Comparing this to the DECODE function, the descriptions seem to be identical.

DECODE compares expr to each search value one by one. If expr is equal
to a search, then Oracle Database returns the corresponding result. If
no match is found, then Oracle returns default. If default is omitted,
then Oracle returns null.

As the searched CASE expression can be equivalent to the simple, this could be construed to be the same as well.

These three statements all seem to return the same result, 0.

select case 1 when 2 then null else 0 end as simple_case
     , case when 1 = 2 then null else 0 end as searched_case
     , decode(1, 2, null, 0) as decode
  from dual

Do the simple CASE expression and the DECODE function (and in specific circumstances the searched CASE expression) always return the same result?

  • 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-06-15T09:18:21+00:00Added an answer on June 15, 2026 at 9:18 am

    Ben has written a lengthy answer on the differences between DECODE and CASE. He demonstrates that DECODE and CASE may return different datatypes for apparently the same set of values without properly explaining why this happens.

    DECODE() is quite prescriptive: it is always the datatype of the first result parameter. Oracle applies implicit conversion to all the other result parameters. It will throw an error , if (say) the first result parameter is numeric and the default value is a date.

    ORA-00932: inconsistent datatypes: expected NUMBER got DATE
    

    This is described in the documentation: find out more.

    In the first scenario the first result parameter is NULL, which Oracle decides to treat as VARCHAR2. If we change it so that the first result parameter is numeric and the default value is null the DECODE() statement will return a NUMBER; a DUMP() proves that this is so.

    Whereas CASE insists that all the returned values have the same datatype, and will throw a compilation error if this is not the case. It won’t apply implicit conversion. This is also covered in the documentation. Read it here.

    The difference boils down to this. The following DECODE statement will run, the CASE statement won’t:

    select decode(1, 1, 1, '1') from dual;
    
    select case 1 when 1 then 1 else '1' end from dual;
    

    Obligatory SQL Fiddle.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This seems like a simple problem: I have a WF4 activity that guides the
This seems like it should have a simple solution but I can't seem to
To me it seems like it should be so simple, but I just feel
To make matter more specific: How to detect people names (seems like simple case
This seems like a simple question, but it is difficult to search for. I
this seems like a simple enough question but I can't seem to find a
This seems like a simple question, but has proven to be difficult to find
I have what seems like a simple arrangement: a list of tags in a
I know it seems like a simple operation, but I can't find any resource
I have what seems like a simple problem. I have a Spring web app,

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.