DECODE() vs CASE
DECODE() vs CASE is a SQL function in the String Functions category. CASE is SQL standard. DECODE is Oracle-specific. CASE is more flexible and portable. The syntax is CASE WHEN condition THEN value ELSE default END. It accepts see syntax. It returns conditional result. A typical example: -- Oracle DECODE: SELECT name, DECODE(department, 'IT', 'Technology', 'HR', 'Human Resources', 'FIN', 'Finance', 'Other' ) FROM employees; -- Portable CASE equivalent: SELECT name, CASE department WHEN 'IT' THEN 'Technology' WHEN 'HR' THEN 'Human Resources' WHEN 'FIN' THEN 'Finance' ELSE 'Other' END AS department_name FROM employees; -- CASE supports complex conditions, DECODE only equality -- CASE can use subqueries, DECODE cannot -- Prefer CASE for portability and readability A close relative is CONCAT(), which concatenates two or more strings into one string. Returns NULL if any argument is NULL. A close relative is SUBSTRING(), which extracts characters from a string starting at position `start` for `length` characters.