Context:FIT2094_MOC · if/else inside a SELECT list · map coded values to readable labels · alias the result column
Problem it solves: return a different output value per row depending on a column’s value.
Quick Revision
🎯 Trigger: “show X as a label” / decode a status code ➔ CASE in the SELECT list; DECODE for pure equality.
⚡ Key Constraint: CASE returns the first matching WHEN; DECODE handles equality only — ranges need CASE.
🔧 Minimal Working Example
SELECT emp_no, emp_fname || ' ' || emp_lname AS emp_name, CASE UPPER(emp_type) WHEN 'F' THEN 'Full Time' WHEN 'C' THEN 'Casual' ELSE 'Unknown' END AS employment_typeFROM drone.employeeORDER BY emp_no;
Expected output: each employee with a human-readable employment_type derived from the emp_type code.
Searched CASE ➔ CASE WHEN cond THEN r … ELSE d END — any predicate, incl. ranges/</>.
Simple CASE ➔ CASE col WHEN v1 THEN r1 … END — equality shorthand.
ELSE optional ➔ unmatched rows return NULL if ELSE is omitted.