CREATE OR REPLACE PROCEDURE UPDATE_AGE_VALUES
IS
cursor_ssn_number tbl_Patient.ssn_number%type;
cursor_patient_age tbl_Patient.patient_age%type;
age1 tbl_Patient.patient_age%type;
age2 tbl_Patient.patient_age%type;
age3 tbl_Patient.patient_age%type;
ssn_number1 tbl_Patient.ssn_number%type;
ssn_number2 tbl_Patient.ssn_number%type;
ssn_number3 tbl_Patient.ssn_number%type;
average number:=0;
i number:=1;
CURSOR cursor_tbl_Patient IS
SELECT ssn_number,patient_age FROM tbl_Patient ORDER BY patient_age ASC;
BEGIN
OPEN cursor_tbl_Patient;
LOOP
FETCH cursor_tbl_Patient into cursor_ssn_number,cursor_patient_age;
EXIT WHEN cursor_tbl_Patient%NOTFOUND;
IF i=1 THEN
age1:=cursor_patient_age;
ssn_number1:=cursor_ssn_number;
i:=i+1;
ELSIF i=2 THEN
age2:=cursor_patient_age;
ssn_number2:=cursor_ssn_number;
i:=i+1;
ELSIF i=3 THEN
age3:=cursor_patient_age;
ssn_number3:=cursor_ssn_number;
average:=(age1+age2+age3)/3;
UPDATE tbl_Patient SET patient_age=average where ssn_number IN (ssn_number1,ssn_number2,ssn_number3);
i:=1;
average:=0;
commit;
END IF;
END LOOP;
CLOSE cursor_tbl_Patient;
END;
/
CREATE OR REPLACE TRIGGER CHANGE_ROW_VALUES
AFTER INSERT ON tbl_Patient
FOR EACH ROW
BEGIN
CALL UPDATE_AGE_VALUES;
END;
/
上面的代码尝试在插入行后修改行值。该过程创建一个execute.But我无法从触发器调用该过程。我不知道为什么。 我得到的错误是: 2/7,PLS-00103:遇到符号“UPDATE_AGE_VALUES”时 ,期待以下之一: ,:=。 (@%; ,符号“:=”代替“UPDATE_AGE_VALUES” ,继续
我错过了什么吗? 提前致谢!!!
答案 0 :(得分:0)
CALL
不是PL / SQL中的有效语句。要在PL / SQL中调用过程,您只需要提供其名称,如:
CREATE OR REPLACE TRIGGER CHANGE_ROW_VALUES
AFTER INSERT ON tbl_Patient
FOR EACH ROW
BEGIN
UPDATE_AGE_VALUES;
END;
您的下一个问题是UPDATE_AGE_VALUES将读取并更新tbl_Patient,这将失败,因为从tbl_Patient上定义的行触发器调用UPDATE_AGE_VALUES。如果你从触发器中移除FOR EACH ROW
它可能会有效,但我不会回答这个问题。
分享并享受。
答案 1 :(得分:0)
CREATE OR REPLACE TRIGGER CHANGE_ROW_VALUES
AFTER INSERT ON tbl_Patient
FOR EACH ROW
BEGIN
UPDATE_AGE_VALUES();
END;
这对我有用!!!