0
0
PostgreSQLquery~10 mins

CASE in PL/pgSQL in PostgreSQL - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to start a CASE expression in PL/pgSQL.

PostgreSQL
DECLARE
  grade CHAR := 'B';
  result TEXT;
BEGIN
  result := CASE [1]
    WHEN 'A' THEN 'Excellent'
    WHEN 'B' THEN 'Good'
    ELSE 'Average'
  END;
END;
Drag options to blanks, or click blank then click option'
ACHAR
Bresult
Cgrade
DTEXT
Attempts:
3 left
💡 Hint
Common Mistakes
Using the variable that stores the result instead of the grade.
Using the data type name instead of a variable.
2fill in blank
medium

Complete the code to use CASE without an expression (searched CASE) in PL/pgSQL.

PostgreSQL
DECLARE
  score INT := 75;
  result TEXT;
BEGIN
  result := CASE
    WHEN score >= [1] THEN 'Pass'
    ELSE 'Fail'
  END;
END;
Drag options to blanks, or click blank then click option'
A50
B90
C100
D60
Attempts:
3 left
💡 Hint
Common Mistakes
Using a passing score that is too high like 90 or 100.
Confusing the comparison operator.
3fill in blank
hard

Fix the error in the CASE expression by completing the missing keyword.

PostgreSQL
DECLARE
  day INT := 3;
  day_name TEXT;
BEGIN
  day_name := CASE day
    [1] 1 THEN 'Monday'
    WHEN 2 THEN 'Tuesday'
    ELSE 'Other'
  END;
END;
Drag options to blanks, or click blank then click option'
ATHEN
BWHEN
CELSE
DIF
Attempts:
3 left
💡 Hint
Common Mistakes
Using IF instead of WHEN inside CASE.
Omitting the WHEN keyword causes syntax errors.
4fill in blank
hard

Fill both blanks to complete the searched CASE expression that categorizes age.

PostgreSQL
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;
Drag options to blanks, or click blank then click option'
A<
B>=
C<=
D>
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong comparison operators that invert the logic.
Mixing up greater than and less than signs.
5fill in blank
hard

Fill all three blanks to complete the CASE expression that assigns a letter grade based on score.

PostgreSQL
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;
Drag options to blanks, or click blank then click option'
A>=
B<
C'C'
D'B'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong comparison operators that cause wrong grade assignment.
Putting the wrong letter grade in the ELSE clause.