Please create a PL/SQL procedure that given a student’s ID, print out name of student and the student’s transcript. On the transcript please include the name of classes the student has taken, the year and semester of the class, and the grade of the class. Please handle the case when the student does not exist. Test your procedure with a student ID you have in your student table.
Tables:
Student table with 2 columns: sid (student ID), sname (student name). • Teacher table with 2 columns: tid (teacher ID), tname (teacher name) • Class table with 6 columns: cid (class ID), cname (class name), year (year of class), semester (semester of class, e.g., fall, spring), credit (number of credits), tid (teacher ID).Grades table with 3 columns: sid (student ID), cid (class ID), grade (grade, 4 is A, 3 is B, 2 is C, 1 is D, 0 is F).
Solution
declare
id student.sid%type;
sn student.sname%type;
cn class.cname%type;
yr class.year%type;
sm class.semester%type;
gd grades.grade%type;
cd grades.cid%type;
begin
id:=&studentid;
select sname into sn from student where sid=id;
select cid,grade into cd,gd from grades where sid=id;
select cname,year,semester into cn,yr,sm from class where cid=cd;
dbms_output.put_line(\'Student Id\'||id);
dbms_output.put_line(\'Student Name\'||sn);
dbms_output.put_line(\'Student Class\'||cn);
dbms_output.put_line(\'Student Year\'||yr);
dbms_output.put_line(\'Student Semester\'||sm);
dbms_output.put_line(\'Student Grade\'||gd);
exception
when no_data_found then
dbms_output.put_line(\'Sorry No Data \');
end;
/
.