Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2003
    Location
    Hickory NC, USA
    Posts
    2

    Unanswered: Noob Procedure Help Problem

    Hello everyone,

    Our teacher gave us an homework assignment for class. He gave us hints but did not help us with all of it. I am pretty sure that I am darn close to having it done but something keeps going wrong. I have to code a procedure that calculates student GPA from the certain tables. Here is the code...

    Create or Replace Procedure NL1(my_last student.s_last%type, my_first student.s_first%type)
    As
    grade_equiv as number(1);
    multiple as number(1);
    totmultiple as number(2);
    totcredits as number(2);
    totgpa as number();
    cursor my_cursor is
    --missing one more join condition in the select statement below
    select Grade, Credits
    from Enrollment, Student, Course, Course_Section
    where S_Last = my_last
    and S_First = my_first
    and Grade is NOT NULL
    and Enrollment.S_ID = Student.S_ID
    and Enrollment.C_SEC_ID = Course_Section.C_SEC_ID
    and Course.COURSE_ID = Course_Section.COURSE_ID
    and Course.Credits = my_row.credits;
    and Course_Section.F_ID = Student.F_ID

    my_row my_cursor%rowtype;

    BEGIN

    For my_row in my_cursor;

    LOOP
    if my_row.grade = 'A'
    then grade_equiv := 4;
    elsif my_row.grade = 'B'
    then grade_equiv := 3;
    elsif my_row.grade = 'C'
    then grade_equiv := 2;
    elsif my_row.grade = 'D'
    then grade_equiv := 1;
    end if;
    multiple := grade_equiv * my_row.credits;
    totmultiple := totmultiple + multiple;
    totcredits := totcredits + my_row.credits;
    totgpa := totcredits / totmultiple;
    dbms_output.put_line('Student Name, GPA');
    dbms_output.put_line('------------------');
    dbms_output.put_line(my_row.s_last ||', '||my_row.s_first || ', '||totgpa;
    END LOOP;
    END;
    /

    Thanks for any help provided guys!

    -Biowaste

  2. #2
    Join Date
    Oct 2003
    Location
    Hickory NC, USA
    Posts
    2
    Oh, and if anyone else would like to help on the 2nd part of the problem, please feel free. This first part is hard enough for me.

    All we have to do is do the same procedure, but make it to where it will show GPA's for all students like this...

    The GPA for John Smith is 3.88
    The GPA for Suzie Jackson is 2.24
    etc...

    till all the students in the table are shown.

    Thanks a lot for any help!

    -Biowaste

  3. #3
    Join Date
    Aug 2003
    Location
    MN
    Posts
    10

    Re: Noob Procedure Help Problem

    I made a lot of changes and modified your select so I could test on my end. Just go through this and compare what I have and what you had. Be careful with you semicolons( you had too many and sometimes not in the right spots. one last thing, your dbms_output wouldn't work because? I'll give you a hint...cursor


    Create or Replace Procedure NL1(my_last stud.last%type, my_first stud.first%type)
    As
    grade_equiv number(1);
    multiple number(2);
    totmultiple number(2) :=0;
    totcredits number(2) :=0;
    totgpa number(2) :=0;
    cursor my_cursor is
    select Grade, Credits, last, first
    from stud
    where last = my_last
    and First = my_first
    and Grade is NOT NULL;

    my_row my_cursor%rowtype;

    BEGIN

    For my_row in my_cursor LOOP
    if my_row.grade = 'A' then
    grade_equiv := 4;
    elsif my_row.grade = 'B' then
    grade_equiv := 3;
    elsif my_row.grade = 'C' then
    grade_equiv := 2;
    elsif my_row.grade = 'D' then
    grade_equiv := 1;
    end if;
    multiple := grade_equiv * my_row.credits;
    totmultiple := totmultiple + multiple;
    totcredits := totcredits + my_row.credits;
    totgpa := totmultiple / totcredits;

    dbms_output.put_line('totm ' || totmultiple);
    dbms_output.put_line('totc ' || totcredits);
    dbms_output.put_line('totgpa ' || totgpa);

    dbms_output.put_line('Student Name, GPA');
    dbms_output.put_line('------------------');
    dbms_output.put_line(my_row.last ||', '||my_row.first || ', '||totgpa);
    END LOOP;
    END;
    /

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •