繁体   English   中英

mysql中的存储过程不起作用

[英]Stored Procedure in mysql Not working

我试图在未插入的情况下插入值,否则尝试更新其某些字段。仅使用一个变量。 虽然离子调用存储过程显示插入一行,但值不插入。 请帮助我,第一次尝试SP。

这是我的存储过程

CREATE DEFINER=`root`@`localhost` PROCEDURE `InsertLocation`(in IpAddress varchar(45))
BEGIN     
  if (SELECT count(*) as count 
      FROM mbuzzz.location_byhits 
      where IpAddress = IpAddress
      having count>0)    
  then     
      UPDATE location_byhits SET Hits=Hits+1 where  IpAddress=IpAddress;    
  else     
      insert into location_byhits(IpAddress,Date_current) 
      values (IpAddress,CURTIME());     
  End if ;    
end

重命名输入参数 ,以便在表示参数和列名称时使数据库引擎清楚。

where IpAddress = IpAddress 

因为引擎认为你将列与自身进行比较,所以总是如此。

尝试

delimiter |
CREATE DEFINER=`root`@`localhost` PROCEDURE `InsertLocation`(in IpAddrParam varchar(45))
BEGIN     
  if ((SELECT count(*) FROM mbuzzz.location_byhits where IpAddress = IpAddrParam)>0)    
  then     
      UPDATE location_byhits SET Hits=Hits+1 where IpAddress=IpAddrParam;    
  else     
      insert into location_byhits(IpAddress,Date_current) 
      values (IpAddrParam, CURTIME());     
  End if ;    
end
|
delimiter ;

暂无
暂无

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

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