PL/SQL Control Statement Exercises: Display the description against a grade using CASE statement with EXCEPTION
PL/SQL Control Statement: Exercise-11 with Solution
Write a PL/SQL program to display the description against a grade using CASE statement with EXCEPTION.
Sample Solution:
PL/SQL Code:
DECLARE
grd CHAR(1);
BEGIN
-- Accept value for grade
grd := '&new_grd';
CASE
WHEN grd = 'A' THEN dbms_output.Put_line('Your Grade is: Outstanding');
WHEN grd = 'B' THEN dbms_output.Put_line('Your Grade is: Excellent');
WHEN grd = 'C' THEN dbms_output.Put_line('Your Grade is: Very Good');
WHEN grd = 'D' THEN dbms_output.Put_line('Your Grade is: Average');
WHEN grd = 'F' THEN dbms_output.Put_line('Your Grade is: Poor');
END CASE;
EXCEPTION
WHEN CASE_NOT_FOUND THEN
dbms_output.Put_line('No such grade in the list.');
END;
/
Sample Output:
Enter value for new_grd: M old 5: grd := '&new_grd'; new 5: grd := 'M'; No such grade in the list. PL/SQL procedure successfully completed.
Flowchart:
Improve this sample solution and post your code through Disqus
Previous: Write a PL/SQL program to display the description against a grade using CASE statement.
Next: Write a PL/SQL program to check whether a given number is positive, negative or zero.
What is the difficulty level of this exercise?
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://w3resource.com/plsql-exercises/control-statement/plsql-control-statement-exercise-11.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics