

More keywords within the statement allow you to break up the logic, rather than using a series of parameters in a single function. Tasks that are hard to implement with DECODE are easy to implement using CASE, which makes it easier to write your SQL. It was introduced into Oracle to replace the DECODE function.ĬASE offers more flexibility than the DECODE function. The ELSE keyword specifies what happens if no condition is met. Many conditions and results can be specified, and if a condition matches the expression, then the result is returned. The expression is used to compare against. The CASE statement in Oracle isn't a function, so I haven't labelled it as one.ĬASE allows you to perform IF-THEN-ELSE logic in your SQL statements, similar to DECODE.

It can handle advanced logic, but can get hard to read as the function gets longer. The DECODE function is an older function, but still quite powerful. Search is compared against the expression, and if it is true, then result is returned. Many combinations of search and result can be supplied. The syntax is: DECODE ( expression, search, result. The DECODE function in Oracle allows you to have IF-THEN-ELSE logic in your SQL statements. It can't change other values, such as 0, or advanced logic compared to CASE and DECODE. The downside is that it only transforms NULL values. It's better than using an NVL function as it takes more parameters, which may be more useful for your code. It's a simple function, and it's helpful as it can take a lot of parameters, and it's easier to write.

Many expressions ( expr1, expr2) can be used. The syntax is: COALESCE ( expr1, expr2, ) The Oracle COALESCE function allows you to return the first non-NULL value from a list of parameters Which one should you use? I'll explain the pros and cons of each in this article. They can transform a value into another value. The Oracle functions CASE, DECODE, and COALESCE all perform similar functionality.
