我在 Oracle SQL Developer 中收到以下错误
PLS-00103:遇到符号“CREATE”
CREATE OR REPLACE PROCEDURE EnrollStudent(
p_StudentID IN INT,
p_CourseID IN INT
) IS
v_student_skill INT;
v_course_skill INT;
v_enrolled_count INT;
BEGIN
SELECT skill INTO v_student_skill
FROM A1_Student
WHERE StudentID = p_StudentID;
SELECT skill INTO v_course_skill
FROM A1_Course
WHERE CourseID = p_CourseID;
IF v_student_skill < v_course_skill THEN
RAISE_APPLICATION_ERROR(-20001, 'Student skill level is not sufficient for this course.');
END IF;
SELECT COUNT(*) INTO v_enrolled_count
FROM A1_Enrollment
WHERE StudentID = p_StudentID AND CourseID = p_CourseID;
IF v_enrolled_count > 0 THEN
RAISE_APPLICATION_ERROR(-20002, 'Student is already enrolled in this course.');
END IF;
INSERT INTO A1_Enrollment (StudentID, CourseID)
VALUES (p_StudentID, p_CourseID);
COMMIT;
DBMS_OUTPUT.PUT_LINE('Student successfully enrolled in the course.');
EXCEPTION
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE('Student or Course not found.');
WHEN OTHERS THEN
ROLLBACK;
DBMS_OUTPUT.PUT_LINE('Error: ' || SQLERRM);
END EnrollStudent;
/
不完全确定为什么会出现此错误,任何帮助将不胜感激。
我将您的代码复制到 SQL Developer 工作表中,运行它并且...
Procedure ENROLLSTUDENT compiled
LINE/COL ERROR
--------- -------------------------------------------------------------
11/5 PL/SQL: SQL Statement ignored
12/10 PL/SQL: ORA-00942: table or view does not exist
15/5 PL/SQL: SQL Statement ignored
16/10 PL/SQL: ORA-00942: table or view does not exist
23/5 PL/SQL: SQL Statement ignored
24/10 PL/SQL: ORA-00942: table or view does not exist
31/5 PL/SQL: SQL Statement ignored
31/17 PL/SQL: ORA-00942: table or view does not exist
Errors: check compiler log
程序编译完成。有错误,但编译通过。出现错误是因为我没有任何这些表。
然后我将以下代码放在我粘贴的代码之前。请注意,这是一个不完整的 pl/sql 代码块。它缺少尾随“/”。
BEGIN
NULL;
END;
并再次运行整个过程。现在的错误是...
...
Error report -
ORA-06550: line 4, column 1:
PLS-00103: Encountered the symbol "CREATE" when expecting one of the following:
...
所以,很可能您在
CREATE OR REPLACE
之前还有一些其他不完整的陈述