- Description: Provides conditional logic for SQL queries.
- Purpose: Replacing complex IF statements.
- Syntax:
CASE WHEN condition THEN result [WHEN ...] [ELSE result] END
- Parameters: Conditions and results as needed.
- Returns: The result corresponding to the first true condition.
- Example:
CASE WHEN score >= 90 THEN 'A' WHEN score >= 80 THEN 'B' ELSE 'F' END
. - Notes: More flexible than DECODE, allowing complex conditions.
- Use Case: Classifying data based on criteria in reports.
Leave a Reply