警告:编译但在sql developer中触发了编译错误

时间:2012-12-08 09:27:47

标签: sql oracle syntax warnings compiled

ALTER TABLE student ADD gpa NUMBER;
CREATE OR REPLACE TRIGGER "USER36401"."GETGPA" AFTER
  DELETE OR
  INSERT OR
  UPDATE ON grade_report FOR EACH row DECLARE totalqp NUMBER :=0;

  totalgpa      NUMBER :=0;
  totalcreds    NUMBER :=0;
  prevqp        NUMBER :=0;
  prevgpa       NUMBER :=0;
  prevcreds     NUMBER :=0;
  incomingqp    NUMBER :=0;
  incominggpa   NUMBER :=0;
  incomingcreds NUMBER :=0;
  temp          NUMBER :=0;
  BEGIN
    CASE
    WHEN updating THEN
      UPDATE student SET student.gpa = NVL(student.gpa,0);
      SELECT student.gpa
      INTO temp
      FROM student
      WHERE student.student_number = :NEW.student_Number;
      IF temp                      <1 THEN
        totalqp                   := temp;
        SELECT DISTINCT DECODE(:NEW.GRADE,'A','4','B','3','C','2','D','1','F','0')
        INTO temp
        FROM student,
          section,
          course
        WHERE :NEW.student_number   = student.student_number
        AND :NEW.section_identifier = section.section_identifier
        AND section.course_number   = course.course_number;
        UPDATE student
        SET student.gpa              = temp
        WHERE student.student_number = :NEW.student_number;
      ELSE
        prevgpa := temp;
        SELECT student.total_credit_hours
        INTO temp
        FROM student
        WHERE student.student_number = :NEW.student_number;

        prevcreds := temp;
        SELECT DISTINCT course.credit_hours
        INTO temp
        FROM course,
          section
        WHERE course.course_number    = section.course_number
        AND section.section_identifier= :NEW.section_identifier;
        --current
        SELECT DISTINCT course.credit_hours
        INTO temp
        FROM course,
          section
        WHERE course.course_number    = section.course_number
        AND section.section_identifier= :NEW.section_identifier;

        incomingcreds := temp;
        prevcreds     := prevcreds - incomingcreds;
        prevqp        := prevgpa   * prevcreds;
        --total quality points before add
        SELECT DECODE(:NEW.GRADE,'A','4','B','3','C','2','D','1','F','0')
        INTO temp
        FROM student,
          section,
          course
        WHERE :NEW.student_number   = student.student_number
        AND :NEW.section_identifier = section.section_identifier
        AND section.course_number   = course.course_number;

        incominggpa := temp;
        --gpa being added before quality points
        SELECT DISTINCT course.credit_hours
        INTO temp
        FROM course,
          section
        WHERE course.course_number    = section.course_number
        AND section.section_identifier= :NEW.section_identifier;

        incomingqp := incominggpa*incomingcreds;
        totalqp    := prevqp     + incomingqp;
        totalcreds := prevcreds  + incomingcreds;
        totalgpa   := totalqp    / totalcreds;
        UPDATE student
        SET gpa                      = totalgpa
        WHERE student.student_number = :NEW.student_number;
      END IF;
    WHEN DELETING then
    Select * from student where student.student_number = :NEW.student_number;
    END CASE;
  END;

目标是触发器在删除时执行“某些[尚未实现]”。

当我编译时,它表示编译,但警告有错误。我被淘汰为决赛周,这是最后一个项目。我无法找到它所处的错误,我确信它是一种语法,我没有发现。非常感谢任何帮助。

编辑:另外,我知道这可能是实现我想要做的事情最无效的方式。但我的代码完全基于教授列出的内容,我们可以在课堂上的powerpoint幻灯片中使用。而且坦率地说,这是我的小专业,而且我是一名大四学生,所以我并不在乎。我只是需要它才能工作。

EDIT3:

来自编译触发器脚本:ALTER TABLE学生成功了。 警告:执行完成并发出警告 TRIGGER“USER36401”。“GETGPA”已编译。

insert into grade_report values ('17','112','B');
select * from student;
insert into grade_report values ('17','119','C');
select * from student;
insert into grade_report values ('8','85','A');
select * from student;
insert into grade_report values ('8','92','A');
select * from student;
insert into grade_report values ('8','102','B');
select * from student;
insert into grade_report values ('8','135','A');

返回错误:“在命令的第1行开始出错: 插入grade_report值('17','112','B') 命令行出错:1列:12 错误报告: SQL错误:ORA-04098:触发器“USER36401.GETGPA”无效且重新验证失败 04098. 00000 - “触发'%s。%s'无效且重新验证失败” *原因:尝试检索触发器以执行并且是            发现无效。这也意味着编译/授权            触发器失败了。 *行动:选项是解决编译/授权错误,            禁用触发器,或放下触发器。“

1 个答案:

答案 0 :(得分:0)

你最后一个select语句(在案例的'delete'分支中),并没有'INTO子句。此外,您使用SELECT *,而您需要指定要在变量中选择的确切字段。

你在案件的另一个分支做同样的事情,为什么不看那个?

相关问题