奇怪的错误,导致我的脚本无法运行
2020-10-01
59
我正在尝试运行下面附加的 pl/sql 过程,在运行脚本时出现以下错误
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 "
3个回答
尝试在您的DBMS前面执行。
exec dbms_output.enable;
Dave Oz
2020-10-01
完全删除第一行 (
DBMS_OUTPUT.ENABLE;
)。
set serveroutput on
(在您即将执行该过程之前)将启用它。
或者,将其封装到过程或匿名 PL/SQL 块本身中,例如
SQL> begin
2 dbms_output.enable;
3 end;
4 /
PL/SQL procedure successfully completed.
SQL>
Littlefoot
2020-10-01