简体   繁体   English

无法使用Mysql -phpMyAdmin中的存储过程更新表

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

I'm using a procedure which is called from a trigger of tableA (say). 我正在使用从tableA的触发器调用的过程(例如)。 In that procedure i am updating another table say tableB. 在该过程中,我正在更新另一个表,即tableB。 But it is not working, I'm not getting any error but the tableB is not updating. 但这不起作用,我没有收到任何错误,但tableB没有更新。 Please help me to resolve this. 请帮助我解决此问题。

Trigger: for tableA BEFORE INSERT 触发器:用于表A插入前

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. 实际上,此过程正在执行,但未更新tableB。

Since you tagged SQL, here's how I'd do it within SQL: 既然您标记了SQL,以下是我在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. -我使用VARCHAR(10)因为您未声明数据类型。 Change it as needed. 根据需要进行更改。
- You used Reg_no and regno in your commands. -您在命令中使用了Reg_noregno Are those column names correct? 这些列名称正确吗?

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

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