Start networking and exchanging professional insights

Register now or log in to join your professional community.

Follow

What is the difference between Decode() and case in Oracle?

user-image
Question added by Manoranjan Hota , Senior IT Analyst , Veritas Corporation
Date Posted: 2016/07/20
Benaoumeur Hadjari
by Benaoumeur Hadjari , Programmer Analyst , Abbott Informatic

They appear to do same task but there are many differences between them: Case can do everything Decode can do and a lot else. Decode is used to substitute code with expression in most of the time. In addition to this decode use only '=' operator and case work with different logical operators. Decode work with expression that are scalar value and case can work with Predicates and sub queries. Case can be also used in PL/SQL in substitute for IF-THEN-ELSE. Case expects data type consistency and decode does not.

anand patel
by anand patel , Technical Lead , HCL Technologies Limited

decode compares the values based on output where as in case output should be match with input.

decode is more easier to read.

case excepts datatype consitency where as decode does not expect datatype consistency.

We can use decode for complicated logical expressions where as case can be used for other conditions except =.

 

 

rahul khajuria
by rahul khajuria , Programmer Analyst , Cognizant

1)DECODE performs an equality check only. CASE is capable of other logical comparisons such as < > etc. It takes some complex coding – forcing ranges of data into discrete form – to achieve the same effect with DECODE.

2) DECODE works with expressions that are scalar values only. CASE can work with predicates and subqueries in searchable form.

Sathish Kumar
by Sathish Kumar , Programmer

Decode was old operator. Oracle introduced case from version 8 or 9.

Decode can change SQL results. So better to use CASE.

ayesha nazir
by ayesha nazir , internee , treet corporation limited

DECODE works with expressions that are scalar values only and But CASE can be used any where even as a parameter of a function and procedure

DECODE works with expressions that are scalar values only and The case function is a much better option because case is More flexible than DECODE, Easier to read and ANSI-compatible

DECODE works with expressions which are scalar values.CASE can work with predicates and subqueries in searchable form.Oracle says CASE executes faster in the optimizer than does DECODE.> We cant use for range(like 2000 to 4000 etc.) in decode, but in case we can.> DECODE can be used Only inside SQL statement....> But CASE can be used any where even as a parameter of a function/procedure> CASE handles NULL values differently.

heidar yousef
by heidar yousef , Analyst Programmer & Team Leader , Municipality of Qatif Municipality - Eastern Region

DECODE works with expressions that are scalar values only. CASE can work with predicates and subqueries in searchable form

Everything DECODE can do, CASE can. There is a lot else CASE can do though, which DECODE cannot. We’ll go through detailed examples in this article.

 

Shahzeb Mokarram
by Shahzeb Mokarram , Software Developer , Sport Ghornatah

DECODE works with expressions that are scalar values only. CASE can work with predicates and subqueries in searchable form.

Khan Mohammad Abdullh Mintu
by Khan Mohammad Abdullh Mintu , Senior Assistant Manager Accounts , Alin Food Products Limited

The difference between decode and case are straightforward. While thedecode operator has been around since the earliest days of Oracle, the caseoperator was introduced in Oracle 8.1.6. While d3code and case can be used interchangeably, the decode is more powerful because decode can change SQL results.

Ramiah RAGU
by Ramiah RAGU , Manager - Information & Technology , T.B.A

The decode and case functions are used within the Oracle database to transform data values for one value to another and the case expression can do all that decode does along with what IF-THEN analysis does

Do you need help in adding the right keywords to your CV? Let our CV writing experts help you.