简体   繁体   English

无法从触发器调用存储过程

[英]Unable to call a stored procedure from the trigger

        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;
        /

Above code tries to modify the row values after a row is inserted. 上面的代码尝试在插入行后修改行值。 The procedure is created a execute.But I'm not able to call the procedure from the Trigger. 该过程创建了一个执行。但是我无法从触发器中调用该过程。 I don't know why. 我不知道为什么 The error I'm getting is : 2/7 ,PLS-00103: Encountered the symbol "UPDATE_AGE_VALUES" when ,expecting one of the following: ,:= . 我收到的错误是:2/7,PLS-00103:预期以下其中一项时遇到符号“ UPDATE_AGE_VALUES”:,:=。 ( @ % ; ,The symbol ":=" was substituted for "UPDATE_AGE_VALUES" to ,continue. (@%;,用符号“:=”代替“ UPDATE_AGE_VALUES”继续。

Am I missing out anything? 我错过了什么吗? Thanks in advance!!! 提前致谢!!!

CALL is not a valid statement in PL/SQL. CALL在PL / SQL中不是有效的语句。 To call a procedure in PL/SQL you just need to give its name, as in: 要在PL / SQL中调用过程,只需提供其名称,如下所示:

 CREATE OR REPLACE TRIGGER CHANGE_ROW_VALUES 
   AFTER INSERT ON tbl_Patient
   FOR EACH ROW    
 BEGIN
   UPDATE_AGE_VALUES;
 END;

Your next problem will be that the UPDATE_AGE_VALUES reads and updates tbl_Patient, which will fail because UPDATE_AGE_VALUES is called from a row trigger which is defined on tbl_Patient. 下一个问题是UPDATE_AGE_VALUES读取并更新tbl_Patient,这将失败,因为从tbl_Patient上定义的行触发器调用UPDATE_AGE_VALUES。 If you remove the FOR EACH ROW from the trigger it might work, but I won't answer for the performance. 如果您从触发器中删除FOR EACH ROW ,它可能会起作用,但是我不会为性能做任何回答。

Share and enjoy. 分享并享受。

  CREATE OR REPLACE TRIGGER CHANGE_ROW_VALUES 
     AFTER INSERT ON tbl_Patient
     FOR EACH ROW    
  BEGIN
     UPDATE_AGE_VALUES();
  END;

This worked for me!!! 这对我有用!!!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM