0

I am trying to run a pl/sql procedure which I have attached 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 variables --
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
"
1
  • 1
    Where are you trying to execute these statements ? In SQL command prompt or any client tool ? Commented Oct 1, 2020 at 5:11

4 Answers 4

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;

Sign up to request clarification or add additional context in comments.

Comments

0

Try exec in front of your dbms..

exec dbms_output.enable;

1 Comment

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.
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>

Comments

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.