0

我想在修改用户表时更新计数器表。

我创建了一个触发器,我将在其中调用此过程。但是这个程序不是创造。请告诉我这个过程中有什么错误。

CREATE PROCEDURE barproc(IN id int,IN val int)
BEGIN
DECLARE @total_products int;

set @total_products=(SELECT COUNT(*)
FROM user where a=id and status='active')

if(@total_products>0)
    update counter
    set b=val
    WHERE a = id and status='active';

END if;
4

1 回答 1

0

尝试

DELIMITER $$
CREATE PROCEDURE barproc(IN id INT, IN val INT)
BEGIN
IF (SELECT COUNT(*)
      FROM `user` 
     WHERE a = id AND `status` = 'active') THEN
    UPDATE counter
       SET b = val
     WHERE a = id AND `status` = 'active';
END IF;
END$$

DELIMITER ;
于 2013-05-18T13:53:58.960 回答