CREATE OR REPLACE TRIGGER TGR_UPT_CGPA
AFTER INSERT ON onlineAssessment
FOR EACH ROW
DECLARE
v_totalCredit NUMBER(3):=0;
v_learnerID VARCHAR(15);
v_grade onlineAssessment.grade%TYPE;
v_gradeNum NUMBER(2);
CURSOR Grade_CURSOR IS
SELECT COUNT(grade), grade
FROM onlineAssessment
WHERE learnerID = :new.learnerID GROUP BY grade;
BEGIN
SELECT learnerID into v_learnerID
FROM onlineAssessment
WHERE AssessmentID = :new.AssessmentID;
SELECT SUM(C.courseCredits) into v_totalCredit
FROM Courses C, onlineAssessment A
WHERE A.learnerID = :new.learnerID AND C.CourseID = A.CourseID;
OPEN Grade_CURSOR;
LOOP
FETCH Grade_CURSOR INTO v_gradeNum, v_grade;
EXIT WHEN Grade_CURSOR%NOTFOUND;
IF v_grade='A' THEN
v_totalCredit := v_totalCredit+(v_gradeNum*4);
ELSIF v_grade='B' THEN
v_totalCredit := v_totalCredit+(v_gradeNum*3);
ELSIF v_grade='C' THEN
v_totalCredit := v_totalCredit+(v_gradeNum*2);
ELSIF v_grade='D' THEN
v_totalCredit := v_totalCredit+(v_gradeNum*2);
ELSE
v_totalCredit := v_totalCredit+(v_gradeNum*0);
END IF;
END LOOP;
CLOSE Grade_CURSOR;
UPDATE learners
SET CGPA = v_totalCredit
WHERE learnerID = :new.learnerID;
END;
/
触发器创建没有问题,但是当我将新数据插入在线评估表时,它不会更新学习者的 CGPA 数据..我无法解决这个问题,请帮助我,谢谢..
我试图弄清楚几乎半天,我无法解决这个问题。我是 Oracle SQL 的新手。