In: Computer Science
PL/SQL
Write a PL/SQL block, using a Case Statement that prints a student’s letter
grade based on the value stored in a variable called grade. Use the ACC
grading system described in the course syllabus to create the block and set
the initial value of grade as 95. Use only one print statement and no
logical operators in your code. Assume a grade can exceed 100, but it
can’t be negative.
Grade Scale:
Grade Scale:
|
|||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
PL/SQL Block:
DECLARE
grade NUMBER := 95;
letter_grade VARCHAR2(2);
BEGIN
letter_grade := CASE
WHEN grade BETWEEN 90 AND 100 THEN 'A'
WHEN grade BETWEEN 80 AND 89 THEN 'B'
WHEN grade BETWEEN 70 AND 79 THEN 'C'
WHEN grade BETWEEN 60 AND 69 THEN 'D'
WHEN grade BETWEEN 0 AND 59 THEN 'F'
ELSE 'NA'
END;
DBMS_OUTPUT.PUT_LINE('Letter grade is ' || letter_grade);
END;
Code Snippet (For Indentation):
Result: