我正在尝试触发更新等级或新插入等级的等级状态。 那是我的桌子
create table Enrollment (
Student_ID char(9) not null,
Course_ID char(5) not null,
Registered_Date date,
Grade NUMBER,
Status varchar(4),
constraint pkEnrollment primary key (Student_ID, Course_ID));
到目前为止,这是我的代码,我不知道问题是什么
create or replace TRIGGER PASS_FAIL
AFTER INSERT OR UPDATE OF GRADE ON ENROLLMENT
DECLARE
CURSOR change_grade IS
select GRADE, STATUS from ENROLLMENT FOR UPDATE;
newgrade ENROLLMENT.GRADE%type;
newstatus ENROLLMENT.STATUS%type;
BEGIN
OPEN change_grade;
LOOP
FETCH change_grade into newgrade,newstatus;
IF newgrade>=60 THEN UPDATE ENROLLMENT SET STATUS = 'Pass' WHERE CURRENT OF change_grade;
ELSE UPDATE ENROLLMENT SET STATUS = 'Fail' WHERE CURRENT OF change_grade;
END IF;
EXIT WHEN change_grade%NOTFOUND;
END LOOP;
CLOSE change_grade;
END;
当我试图改变成绩时我得到了
UPDATE "FELIX"."ENROLLMENT" SET GRADE = '10' WHERE ROWID = 'AAAGETAABAAALKJAAE' AND ORA_ROWSCN = '3332070'
ORA-04098: trigger 'FELIX.ELIGIBLE_ENROLLMENT' is invalid and failed re-validation
One error saving changes to table "FELIX"."ENROLLMENT":
Row 5: ORA-04098: trigger 'FELIX.ELIGIBLE_ENROLLMENT' is invalid and failed re-validation
提前感谢您的帮助
答案 0 :(得分:1)
除非要了解游标,否则您的代码似乎过于复杂。
CREATE OR REPLACE TRIGGER PASS_FAIL
Before INSERT OR UPDATE
ON enrollment
REFERENCING NEW AS New OLD AS Old
FOR EACH ROW
DECLARE
/******************************************************************************
NAME: PASS_FAIL
PURPOSE:
USED BY:
REVISIONS:
Ver Date Author Description
--------- ---------- --------------- ------------------------------------
1.0 1. Created this trigger.
NOTES:
******************************************************************************/
BEGIN
if :new.grade > 60 THEN
:new.status := 'PASS';
ELSE
:new.status := 'FAIL';
END IF;
EXCEPTION
WHEN OTHERS
THEN
-- Log the error and then re-raise
RAISE;
END PASS_FAIL;