0

I am trying to run a pl/sql procedure which I have attatched below, and am getting the following error when running my script

DBMS_OUTPUT.ENABLE;

create or replace procedure grade_point212
is
cursor c1 is
----Cursor declaration--
SELECT student.student_id, student.first_name, student.last_name, course.course_id, course.course_name, class.grade
FROM CLASS
JOIN STUDENT
  ON student.student_id = class.student_id
  JOIN course
  ON course.course_id = class.course_id
order by 1;
----Variable declation--
v_student_id student.student_id%type;
v_first_name  student.first_name%type;
v_last_name student.last_name%type;
v_course_id course.course_id%type;
v_course_name course.course_name%type;
v_grade class.grade%type;
--3 additional varriables--
prev_student student.student_id%type;
course_count  number(3);
grade_point_total  number(3);
----mainline--
begin
    open c1; 
    loop
--Get the first row in the cursor--
    fetch c1 
    into v_student_id,v_first_name ,v_last_name,v_course_id,v_course_name,v_grade;
    exit when c1%notfound;
--Set the prev_student to the cursor’s student id--
        prev_student:=v_student_id;
--Set the grade_point _total to 0--
        grade_point_total:=0;
--Set the course_count to 0--
        course_count:=0;
--If the prev_studentis NOT equal to cursor’s student id--
            IF prev_student!=v_student_id  THEN
--Print out the grade point average which is grade_point_total divided by course_count--
                DBMS_OUTPUT.PUT_LINE(grade_point_total/course_count); 
--Set prev_student to the cursor’s student id--
                prev_student:=v_student_id;
--Set the grade_point_total to 0--
                grade_point_total:=0;
--Set the course_count to 0--
                course_count:=0;
            END IF;
--Add the grade point of the cursor’s grade to grade_point_total--
grade_point_total:=grade_point_total+GradePoint(v_grade);
--Add 1 to the course_count--
course_count:=course_count+1;
--Print out the current row--
 DBMS_OUTPUT.PUT_LINE(v_student_id||' '||v_first_name||' '||v_last_name||' '||v_course_id||' '||v_course_name||' '||v_grade); 
--Fetch a new row--
 fetch c1 
 into v_student_id,v_first_name ,v_last_name,v_course_id,v_course_name,v_grade;
end loop; 
--Close the cursor--
close c1; 
--Print out the grade point average which is grade_point_total divided by course_count--
DBMS_OUTPUT.PUT_LINE(grade_point_total/course_count);
end;


set serveroutput on;
begin
 grade_point212;
end;
"Error starting at line : 1 in command -
DBMS_OUTPUT.ENABLE
Error report -
Unknown Command


Procedure GRADE_POINT212 compiled

LINE/COL  ERROR
--------- -------------------------------------------------------------
65/1      PLS-00103: Encountered the symbol "SET" 
Errors: check compiler log
"
Thorsten Kettner
  • 89,309
  • 7
  • 49
  • 73
some dude
  • 15
  • 4

4 Answers4

1

The "/" is correct. As a follow up, what tool you are using to send your scripts to the database?

SQL*Plus uses the standalone "/" line as the indicator that the sequence of strings is complete and therefore can be sent to the database for compilation and execution. If you don't provide the "/" you will get errors that on closer read will indicate that some compilation has failed because the sequence you send will actually be composed of multiple SQL, SQL*Plus, and PLSQL blocks.

The execute keyword, BTW, as in:

exec dbms_output.enable;

is SQLPlus syntactic sugar that gets converted by SQLPlus into:

begin dbms_output.enable; end;

B Cheng
  • 121
  • 3
0

Try exec in front of your dbms..

exec dbms_output.enable;

Dave Oz
  • 11
  • 1
  • 3
  • doesnt work I get the same error, i think I maybe having a syntax mistake. I am checking it over to see if I can figure this out. – some dude Oct 01 '20 at 03:49
0

Remove the first line (DBMS_OUTPUT.ENABLE;) entirely. set serveroutput on (before you're about to execute the procedure) will enable it.

Or, encapsulate it into the procedure or the anonymous PL/SQL block itself, e.g.

SQL> begin
  2    dbms_output.enable;
  3  end;
  4  /

PL/SQL procedure successfully completed.

SQL>
Littlefoot
  • 131,892
  • 15
  • 35
  • 57
0

You missed the trailing "/" to execute the "CREATE OR REPLACE" statement. The ";" As explained here, the semi-colon ends your pl/sql statement but you need the slash to execute it.

The error "Encountered the symbol "SET" Errors: check compiler log " refers to the "SET" string from the "set serveroutput on" statement.

...
DBMS_OUTPUT.PUT_LINE(grade_point_total/course_count);
end;
/  <<< Add this 

set serveroutput on;
begin
 grade_point212;
end;
/  <<< Add this
Koen Lostrie
  • 14,938
  • 2
  • 13
  • 19