DECODE Function
The DECODE function in Oracle SQL is a conditional expression that compares an expression (expr) to a specified value (val). If the two match, it returns a specified result (res). It serves as a concise alternative to the if-else statement in procedural languages.
Syntax:
DECODE(expr, val, res)
Parameters:
- expr: The expression to search the value in.
- val: The value to search in the expression.
, - res: The value to return if the search is successful.
Example:
The following query returns ‘found‘ if the current year is 2024.
SELECT CURRENT_DATE, DECODE(EXTRACT(YEAR FROM CURRENT_DATE), 2024, 'found') FROM DUAL;
Output:
How Efficiently Convert Rows to Columns in PL/SQL?
PL/SQL, or Procedural Language/Structured Query Language, is an extension of SQL used for writing procedural code within Oracle databases. It is a proprietary procedural extension of SQL developed by Oracle Corporation specifically for Oracle Database.
It combines the power of SQL with procedural constructs like loops, conditions, and exception handling. It is a blocked programming language, programming units can be named or unnamed blocks. Unnamed blocks are never stored in the database.
Contact Us