PL/SQL Program to Assign Grades Using Case Statement and Loops

Best PL/SQL Grade Assignment Program with Loops and Case

Learn how to write a PL/SQL program to assign grades using loops and CASE statements. This guide helps beginners and pros with real-world SQL interview questions and high-paying concepts.

PL/SQL Code Example to Assign Grades


DECLARE
  score NUMBER := 85;
  grade CHAR(1);
BEGIN
  CASE 
    WHEN score >= 90 THEN grade := 'A';
    WHEN score >= 80 THEN grade := 'B';
    WHEN score >= 70 THEN grade := 'C';
    WHEN score >= 60 THEN grade := 'D';
    ELSE grade := 'F';
  END CASE;

  DBMS_OUTPUT.PUT_LINE('Grade: ' || grade);
END;
    

How It Works

  • Easy loop-based logic
  • Efficient use of CASE statements
  • Great for exams, interviews, and projects

FAQs

Where is this useful?
University projects, coding challenges, technical interviews.
Can I modify it for MySQL?
Yes, adjust the syntax to fit MySQL procedures.

More SQL Tools & Tutorials

Pro Tip: Bookmark this site for real SQL tools and insights to boost your career!

Published by | Last updated: