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;
目標は、トリガーが削除時に「何か[まだ実装されていない]」を実行することです。
コンパイルすると、コンパイルと表示されますが、エラーで警告されます。私は最終週のために地獄のように燃え尽きました、そしてこれは最後のプロジェクトです. どこにエラーがあるのか わかりません。私が見つけていない構文上の問題だと確信しています。どんな助けでも大歓迎です。
編集:また、これはおそらく私がやろうとしていることを実装するための最も非効率的な方法であることを理解しています. しかし、私のコードは、クラスのパワーポイント スライドで使用できる教授がリストしたものに完全に基づいています。率直に言って、これは私のマイナーな専門分野であり、私はシニアなので、あまり気にしません。私はそれが機能する必要があります。
編集3:
コンパイル トリガー スクリプトから: 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' は無効であり、再検証に失敗しました" 。これは、トリガーのコンパイル/承認が失敗したことも意味します。*アクション: オプションは、コンパイル/承認エラーの解決、トリガーの無効化、またはトリガーの削除です。