我的ADMITED_TABLE表包含(NOSTUDENT,COURSECODE,SEMESTER,NOGROUPE,MARK)列。即使在創建INSTEAD OF UPDATE TRIGGER後更新視圖也不合法
我想要做什麼:
當更新excecuted我想通過oldavg和newavg差異性之探源增加關注 學生大關。
Eg: newavg - oldavg = 10.
every student of that cours get MARK+10
雷馬克:是否有可能更新在這種情況下 AVGMARK這僅僅是給AVG(MARK)名字的沒有列值?
UPDATE AverageByGroup SET AVGMARK = (AVGMARK + 10) -- error is her
WHERE COURSCODE = 'AAAA'
AND NOGROUPE = 111
AND SEMESTER = 0000;
結果:
我應該在ADMITED_TABLE關注學生的舊痕+ 10
錯誤,請參閱:
SQL : ORA-01732: data manipulation operation not legal on this view
01732. 00000 - "data manipulation operation not legal on this view"
我的觀點的作品和我的TRIGGER編譯沒有錯誤
-- CREATION OF THE VIEW
CREATE OR REPLACE VIEW AverageByGroup AS
SELECT COURSCODE, NOGROUPE, SEMESTER, AVG(MARK) AS AVGMARK
FROM ADMITED_TABLE GROUP BY COURSECODE,NOGROUPE,SEMESTER;
-- TRIGGER INSTEAD OF UPDATE
CREATE OR REPLACE TRIGGER changeStudentsMarks
INSTEAD OF UPDATE ON AverageByGroupe
FOR EACH ROW
DECLARE
-- UPDATE CURSOR
CURSOR c_students IS
SELECT * FROM ADMITED_TABLE WHERE
COURSCODE = :NEW.COURSCODE
AND NOGROUPE = :NEW.NOGROUPE
AND SEMESTER = :NEW.SEMESTER
FOR UPDATE OF MARK;
rec_students c_students%ROWTYPE;
v_actual_avg INTEGER;
V_new_avg INTEGER;
v_diff INTEGER;
BEGIN
-- Affectationa
v_actual_avg := :OLD.AVGMARK;
v_new_avg := :NEW.AVGMARK;
v_diff := v_new_avg - v_actual_avg;
OPEN c_students;
LOOP
FETCH c_students INTO rec_students;
EXIT WHEN c_students%NOTFOUND;
v_maj_note_etudiant := rec_etudiants.NOTE + v_diff -- add the diffrence to student mark
UPDATE ADMITED_TABLE
SET MARK = MARK + v_maj_note_etudiant
WHERE CURRENT OF c_students;
END LOOP;
CLOSE c_students;
END;
/
表名:'AverageByGroup'。觸發器中的表格名稱:'AverageByGroupe'。錯字? –
因此,如果你的觸發器工作正確,你想要什麼,那麼問題是什麼?你需要什麼幫助? – arturro
我想通過在視圖中添加10來更新avgmark,因此在此之後觸發器會觸發並添加到每個學生的標記10.我需要的幫助是找到一種方法來實現此目的。 –