w3resource
PL/SQL Control Statement Exercises

PL/SQL Control Statement Exercises: Display the description against a grade using CASE statement

PL/SQL Control Statement: Exercise-10 with Solution

Write a PL/SQL program to display the description against a grade using CASE statement.

Sample Solution:

PL/SQL Code:

DECLARE
    grd CHAR(1);
  BEGIN
    -- Accept value for grade
    grd := '&new_grd';
  CASE grd
    WHEN 'A' THEN dbms_output.Put_line('Your Grade is: Outstanding');
    WHEN 'B' THEN dbms_output.Put_line('Your Grade is: Excellent');
    WHEN 'C' THEN dbms_output.Put_line('Your Grade is: Very Good');
    WHEN 'D' THEN dbms_output. Put_line('Your Grade is: Average');
    WHEN 'F' THEN dbms_output.Put_line('Your Grade is: Poor');
    ELSE dbms_output.Put_line('No such grade in the list.');
  END CASE;	
  END;
/

Sample Output:

Enter value for new_grd: D
old   5:     grd := '&new_grd';
new   5:     grd := 'D';
Your Grade is: Average

PL/SQL procedure successfully completed.

Flowchart:

Flowchart: PL/SQL Control Statement Exercises: Display the description against a grade using CASE statement

Improve this sample solution and post your code through Disqus

Previous: Write a PL/SQL program to count number of employees in a specific department and check whether this department have any vacancies or not.
Next: Write a PL/SQL program to display the description against a grade using CASE statement with EXCEPTION.

What is the difficulty level of this exercise?