创建过程 sql 成功但编译错误
create procedure sql success with compilation error
我是 sql 的初学者,正在学习过程、函数和匿名块。我检查了我的代码,没有发现拼写错误导致编译错误。你能帮我理解我在这里做错了什么吗?本题4.将文件show_class_offerings.sql转换为程序。接受开始日期和结束日期。对于找到的每个 class,显示 CLASS_ID、START_DATE、讲师 FIRST_NAME 和 LAST_NAME、课程名称和 SECTION_CODE 以及平均成绩。通过调用函数 compute_average_grade.
查找平均成绩
CREATE OR REPLACE PROCEDURE show_class_offerings
(p_start_date IN DATE,
p_end_date IN DATE)
IS
v_avg_grade NUMBER;
IS
CURSOR classes_info_cur IS
SELECT cl.class_id, cl.start_date, i.first_name,
i.last_name, co.title, co.section_code
FROM classes cl, courses co, instructors i
WHERE start_date BETWEEN p_start_date AND p_end_date
AND cl.course_id = co.course_id
AND cl.instr_id = i.instructor_id;
BEGIN
DBMS_OUTPUT.PUT_LINE ('Date range: Between ' ||
p_start_date || ' and ' || p_end_date || '.');
DBMS_OUTPUT.PUT_LINE('Classes Information.');
FOR classes_info_rec IN classes_info_cur
LOOP
v_avg_grade := compute_average_grade(classes_info_rec.class_id);
DBMS_OUTPUT.PUT_LINE(
'Class ID' || classes_info_rec.class_id ||
'-Average Grade' || v_avg_grade ||
'-Start Date' || classes_info_rec.start_date ||
'-Instructor' || classes_info_rec.first_name ||
classes_info_rec.last_name ||
'-Course Title' || classes_info_rec.title ||
'-Offering Section' || classes_info_rec.section_code);
END LOOP;
END show_class_offerings;
错误:ORA-24344:成功,但出现编译错误
删除第二个IS
:
CREATE OR REPLACE PROCEDURE show_class_offerings(
p_start_date IN DATE,
p_end_date IN DATE
)
IS
v_avg_grade NUMBER;
CURSOR classes_info_cur IS
SELECT cl.class_id,
cl.start_date,
i.first_name,
i.last_name,
co.title,
co.section_code
FROM classes cl
INNER JOIN courses co
ON (cl.course_id = co.course_id)
INNER JOIN instructors i
ON (cl.instr_id = i.instructor_id)
WHERE start_date BETWEEN p_start_date AND p_end_date;
BEGIN
DBMS_OUTPUT.PUT_LINE (
'Date range: Between ' || p_start_date || ' and ' || p_end_date || '.'
);
DBMS_OUTPUT.PUT_LINE('Classes Information.');
FOR classes_info_rec IN classes_info_cur
LOOP
v_avg_grade := compute_average_grade(classes_info_rec.class_id);
DBMS_OUTPUT.PUT_LINE(
'Class ID' || classes_info_rec.class_id ||
'-Average Grade' || v_avg_grade ||
'-Start Date' || classes_info_rec.start_date ||
'-Instructor' || classes_info_rec.first_name || classes_info_rec.last_name ||
'-Course Title' || classes_info_rec.title ||
'-Offering Section' || classes_info_rec.section_code
);
END LOOP;
END show_class_offerings;
/
(注意:您也可以使用 ANSI 联接代替可读性较差的旧式逗号联接。)
db<>fiddle here
我是 sql 的初学者,正在学习过程、函数和匿名块。我检查了我的代码,没有发现拼写错误导致编译错误。你能帮我理解我在这里做错了什么吗?本题4.将文件show_class_offerings.sql转换为程序。接受开始日期和结束日期。对于找到的每个 class,显示 CLASS_ID、START_DATE、讲师 FIRST_NAME 和 LAST_NAME、课程名称和 SECTION_CODE 以及平均成绩。通过调用函数 compute_average_grade.
查找平均成绩CREATE OR REPLACE PROCEDURE show_class_offerings
(p_start_date IN DATE,
p_end_date IN DATE)
IS
v_avg_grade NUMBER;
IS
CURSOR classes_info_cur IS
SELECT cl.class_id, cl.start_date, i.first_name,
i.last_name, co.title, co.section_code
FROM classes cl, courses co, instructors i
WHERE start_date BETWEEN p_start_date AND p_end_date
AND cl.course_id = co.course_id
AND cl.instr_id = i.instructor_id;
BEGIN
DBMS_OUTPUT.PUT_LINE ('Date range: Between ' ||
p_start_date || ' and ' || p_end_date || '.');
DBMS_OUTPUT.PUT_LINE('Classes Information.');
FOR classes_info_rec IN classes_info_cur
LOOP
v_avg_grade := compute_average_grade(classes_info_rec.class_id);
DBMS_OUTPUT.PUT_LINE(
'Class ID' || classes_info_rec.class_id ||
'-Average Grade' || v_avg_grade ||
'-Start Date' || classes_info_rec.start_date ||
'-Instructor' || classes_info_rec.first_name ||
classes_info_rec.last_name ||
'-Course Title' || classes_info_rec.title ||
'-Offering Section' || classes_info_rec.section_code);
END LOOP;
END show_class_offerings;
错误:ORA-24344:成功,但出现编译错误
删除第二个IS
:
CREATE OR REPLACE PROCEDURE show_class_offerings(
p_start_date IN DATE,
p_end_date IN DATE
)
IS
v_avg_grade NUMBER;
CURSOR classes_info_cur IS
SELECT cl.class_id,
cl.start_date,
i.first_name,
i.last_name,
co.title,
co.section_code
FROM classes cl
INNER JOIN courses co
ON (cl.course_id = co.course_id)
INNER JOIN instructors i
ON (cl.instr_id = i.instructor_id)
WHERE start_date BETWEEN p_start_date AND p_end_date;
BEGIN
DBMS_OUTPUT.PUT_LINE (
'Date range: Between ' || p_start_date || ' and ' || p_end_date || '.'
);
DBMS_OUTPUT.PUT_LINE('Classes Information.');
FOR classes_info_rec IN classes_info_cur
LOOP
v_avg_grade := compute_average_grade(classes_info_rec.class_id);
DBMS_OUTPUT.PUT_LINE(
'Class ID' || classes_info_rec.class_id ||
'-Average Grade' || v_avg_grade ||
'-Start Date' || classes_info_rec.start_date ||
'-Instructor' || classes_info_rec.first_name || classes_info_rec.last_name ||
'-Course Title' || classes_info_rec.title ||
'-Offering Section' || classes_info_rec.section_code
);
END LOOP;
END show_class_offerings;
/
(注意:您也可以使用 ANSI 联接代替可读性较差的旧式逗号联接。)
db<>fiddle here