包创建错误

时间:2016-03-30 07:28:51

标签: sql oracle

我正在尝试构建一个允许我在表格中插入成绩的包。老师有一些他们教的课程,我想在老师想把一个年级分到他们不教的课堂时提出异常。 这是我的代码:

CREATE OR REPLACE PACKAGE manager_facultate IS
     PROCEDURE inserare_nota (nr_matr studenti.nr_matricol%type, nume profesori.nume%type, id_curs note.id_curs%type, valoarea note.valoare%type);
END manager_facultate;
/

CREATE OR REPLACE PACKAGE BODY manager_facultate IS

    FUNCTION returneaza_id_curs (id_curs NUMBER) RETURN NUMBER IS
    BEGIN
        CURSOR c1 (nume) IS
           SELECT d.id_curs from didactic d JOIN profesori p ON d.id_prof=p.id_prof
           WHERE p.nume=nume;
    END returneaza_id_curs;

    PROCEDURE inserare_nota (nr_matr studenti.nr_matricol%type, nume profesori.nume%type, id_curs note.id_curs%type, valoarea note.valoare%type) IS
    v_id NUMBER(3);
    BEGIN
    INSERT INTO note VALUES (nr_matr, id_curs, valoare, NULL);
    EXCEPTION
    WHEN id_gresit THEN
        v_id :=returneaza_id_curs(nume);
        IF id_curs <> v_id THEN
           raise_application_error (-20002, 'Profesorul nu preda acest curs');
        END IF;
    END inserare_nota;

END manager_facultate;
/

当我想创建我的包体时,我收到了这个错误。

LINE/COL ERROR
-------- -----------------------------------------------------------------
5/16     PLS-00103: Encountered the symbol "C1" when expecting one of the
         following:
         := . ( @ % ;
         The symbol ":=" was substituted for "C1" to continue.

6/12     PLS-00103: Encountered the symbol "SELECT" when expecting one of
         the following:
         not null of nan infinite dangling a empty

6/45     PLS-00103: Encountered the symbol "JOIN" when expecting one of
         the following:

LINE/COL ERROR
-------- -----------------------------------------------------------------
         , ; for group having intersect minus order start union where
         connect

我做错了什么?

1 个答案:

答案 0 :(得分:0)

如果您有适当的表和外键,则不需要过程:

CREATE TABLE People (
  ID         INT PRIMARY KEY,
  First_Name VARCHAR2(100),
  Last_Name  VARCHAR2(100)
);

CREATE TABLE Students(
  ID              INT PRIMARY KEY REFERENCES People( ID ),
  Enrollment_Date DATE
);

CREATE TABLE Staff(
  ID     INT PRIMARY KEY REFERENCES People( ID ),
  Salary NUMBER,
  Office VARCHAR2(10)
);

CREATE TABLE Courses(
  ID     INT PRIMARY KEY,
  Title  VARCHAR2(50)
);

CREATE TABLE Course_Teachers(
  ProfessorID INT REFERENCES Staff( ID ),
  CourseID    INT REFERENCES Courses( ID ),
  Class_Name  VARCHAR2(50),
  PRIMARY KEY ( ProfessorID, CourseID )
);

CREATE TABLE Enrollments(
  ProfessorID INT,
  CourseID    INT,
  StudentID   INT REFERENCES Students ( ID ),
  FOREIGN KEY ( ProfessorID, CourseID ) REFERENCES Course_Teachers ( ProfessorID, CourseID ),
  PRIMARY KEY ( ProfessorID, CourseID, StudentID )
);

CREATE TABLE Assignments(
  ProfessorID      INT REFERENCES Staff( ID ),
  CourseID         INT REFERENCES Courses( ID ),
  AssignmentNumber INT,
  GradePercentage  INT,
  Name             VARCHAR2(50),
  FOREIGN KEY ( ProfessorID, CourseID ) REFERENCES Course_Teachers ( ProfessorID, CourseID ),
  PRIMARY KEY ( ProfessorID, CourseID, AssignmentNumber )
);

CREATE TABLE Grades(
  ProfessorID      INT REFERENCES Staff( ID ),
  CourseID         INT REFERENCES Courses( ID ),
  StudentID        INT REFERENCES Students ( ID ),
  AssignmentNumber INT,
  Grade            INT,
  FOREIGN KEY ( ProfessorID, CourseID, StudentID ) REFERENCES Enrollments ( ProfessorID, CourseID, StudentID ),
  FOREIGN KEY ( ProfessorID, CourseID, AssignmentNumber ) REFERENCES Assignments ( ProfessorID, CourseID, AssignmentNumber ),
  PRIMARY KEY ( ProfessorID, CourseID, StudentID, AssignmentNumber )
);