Complete the code to start a CASE expression in PL/pgSQL.
DECLARE grade CHAR := 'B'; result TEXT; BEGIN result := CASE [1] WHEN 'A' THEN 'Excellent' WHEN 'B' THEN 'Good' ELSE 'Average' END; END;
The CASE expression evaluates the variable grade to decide the result.
Complete the code to use CASE without an expression (searched CASE) in PL/pgSQL.
DECLARE score INT := 75; result TEXT; BEGIN result := CASE WHEN score >= [1] THEN 'Pass' ELSE 'Fail' END; END;
The searched CASE checks if score is greater or equal to 50 to pass.
Fix the error in the CASE expression by completing the missing keyword.
DECLARE day INT := 3; day_name TEXT; BEGIN day_name := CASE day [1] 1 THEN 'Monday' WHEN 2 THEN 'Tuesday' ELSE 'Other' END; END;
Each condition in a CASE expression must start with the WHEN keyword.
Fill both blanks to complete the searched CASE expression that categorizes age.
DECLARE age INT := 25; category TEXT; BEGIN category := CASE WHEN age [1] 18 THEN 'Minor' WHEN age [2] 18 THEN 'Adult' ELSE 'Senior' END; END;
The first condition checks if age is less than 18 for 'Minor'. The second checks if age is greater or equal to 18 for 'Adult'.
Fill all three blanks to complete the CASE expression that assigns a letter grade based on score.
DECLARE score INT := 85; grade CHAR; BEGIN grade := CASE WHEN score [1] 90 THEN 'A' WHEN score [2] 80 THEN 'B' ELSE [3] END; END;
The CASE assigns 'A' if score is 90 or more, 'B' if score is 80 or more, else 'C'.