CASE is better to understand than DECODE

Software ResiliencyProgramming Best Practices

Why you should care

The DECODE function belongs to PLSQL and has the functionality of an IF-THEN statement. It’s syntax is as follows DECODE( expression , search , result [, search , result]…[, default] )
expression – The value to compare
search – The value is compared against expression
result – The value returned, if expression is equal to search
default – Optional. If not matches are found, the DECODE function will return default. If default is omitted, then the DECODE function will return null (if no matches are found).
With that being said, CASE is a better function as it is simpler to write and can be used in PL/SQL. CASE is easier to read, understand and maintain the code.

Business Impacts

DECODE function is an old function replaced by CASE because the latter is less risky to use and more productive. This is because CASE is easier to read, understand and maintain.

Production Risk
5362

How we detect

This code insight shows that DECODE is an old function that has been replaced by the easier-to-understand and more common CASE function. Contrary to the DECODE statement CASE may also be used directly within PL/SQL

5362

About CAST and Highlight’s Code Insights

Over the last 25 years, CAST has leveraged unique knowledge on software quality measurement by analyzing thousands of applications and billions of lines of code. Based on this experience and community standards on programming best practices, Highlight implements hundreds of code insights across 15+ technologies to calculate health factors of a software.

See featuresHow it works