简体   繁体   中英

Can't update table using stored procedure in Mysql -phpMyAdmin

I'm using a procedure which is called from a trigger of tableA (say). In that procedure i am updating another table say tableB. But it is not working, I'm not getting any error but the tableB is not updating. Please help me to resolve this.

Trigger: for tableA BEFORE INSERT

BEGIN
   CALL his_arrear(new.Reg_No,new.Sub_Code);
END

Procedure:

BEGIN
   DECLARE toup integer;
    select count(*) into toup from tableA where Reg_No=reg and Sub_Code=scode;
    update tableB set his_arrear=toup where regno=reg;
END

Actually here the procedure is executing but it is not updating the tableB.

Since you tagged SQL, here's how I'd do it within SQL:

ALTER PROCEDURE his_arrear
    @reg VARCHAR(10),
    @scode VARCHAR(10)
AS
BEGIN
    DECLARE @toup INTEGER;

    SELECT COUNT(*) AS @toup
    FROM tableA
    WHERE Reg_No=@reg AND Sub_Code=@scode;

    UPDATE tableB
    SET his_arrear=ISNULL(@toup,0)
    WHERE regno=@reg;
END

Notes:
- I used VARCHAR(10) as you did not state your data types. Change it as needed.
- You used Reg_no and regno in your commands. Are those column names correct?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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