程序包编译失败并显示 ORA-00927:缺少等号

Package compilation fails with ORA-00927: missing equal sign

我正在创建一个包,但我不明白为什么会出现错误。 我的包裹:

create or replace PACKAGE test_action AS
    subj CHAR default '';
    count_student INTEGER default 0;
    FUNCTION count_positive(subject CHAR) RETURN INTEGER;
    PROCEDURE number_requests;
END test_action;

包体:

CREATE OR REPLACE PACKAGE BODY test_action AS
    FUNCTION count_positive(sub CHAR) RETURN INTEGER
    AS
    BEGIN 
        count_student := 0;
        subj := sub;
        SELECT COUNT(*) INTO count_student 
        FROM D8_EXAMS E JOIN D8_SUBJECT S 
        ON E.subj_id = S.subj_id
        WHERE E.mark > 3 AND S.subj_name = subject
        GROUP BY S.subj_name;
        number_requests;          
        return count_student;
    END count_positive; 
    PROCEDURE number_requests AS
    BEGIN
        INSERT INTO package_table (subject,counts,callCount)
                VALUES (subj,count_student,1);
        exception
            when dup_val_on_index then
                update t 
                set    callCount := callCount + 1,
                set     counts := count_student
                where  subject = subj;
    END number_requests;   
END test_action;

然后我得到一个错误

如果我尝试在函数描述之前添加对变量的赋值,则会出现新的错误

因为 - 如错误所说 - 您缺少等号(只是 =,而不是 :=),并且每个 [=16= 只有一个 set 关键字]:

update t 
   set    callCount = callCount + 1,
          counts    = count_student
   where  subject   = subj;

除此之外:

  • 包体中的函数声明必须与包规范中的函数声明相匹配
  • 在例外情况下,您正在更新 table t;不应该是package_table吗?
  • select count(*)group by 子句;对我来说,这听起来像是引发 too_many_rows 你没有处理的错误的可能点

这至少编译:包规范:

SQL> CREATE OR REPLACE PACKAGE test_action
  2  AS
  3     subj           CHAR DEFAULT '';
  4     count_student  INTEGER DEFAULT 0;
  5
  6     FUNCTION count_positive (sub CHAR)
  7        RETURN INTEGER;
  8
  9     PROCEDURE number_requests;
 10  END test_action;
 11  /

Package created.

包体:

SQL> CREATE OR REPLACE PACKAGE BODY test_action
  2  AS
  3     FUNCTION count_positive (sub CHAR)
  4        RETURN INTEGER
  5     AS
  6     BEGIN
  7        count_student := 0;
  8        subj := sub;
  9
 10          SELECT COUNT (*)
 11            INTO count_student
 12            FROM D8_EXAMS E JOIN D8_SUBJECT S ON E.subj_id = S.subj_id
 13           WHERE     E.mark > 3
 14                 AND S.subj_name = sub
 15        GROUP BY S.subj_name;
 16
 17        number_requests;
 18        RETURN count_student;
 19     END count_positive;
 20
 21     PROCEDURE number_requests
 22     AS
 23     BEGIN
 24        INSERT INTO package_table (subject, counts, callCount)
 25             VALUES (subj, count_student, 1);
 26     EXCEPTION
 27        WHEN DUP_VAL_ON_INDEX
 28        THEN
 29           UPDATE package_table
 30              SET callCount = callCount + 1, counts = count_student
 31            WHERE subject = subj;
 32     END number_requests;
 33  END test_action;
 34  /

Package body created.

SQL>