繁体   English   中英

MySQL存储过程不起作用

[英]MySQL stored procedure is not working

我是Mysql的新手。 我有一个存储过程,下面是我的SP

CREATE DEFINER=`root`@`localhost` PROCEDURE `insertGroup`(IN startdate date, 
IN  enddate date, 
 IN  amount int, 
IN  groupname char(50))
BEGIN

DECLARE c_id INT; 

set c_id  =(select  id from c_begin where startdate = startdate and enddate = enddate and amount = amount);


insert into c_group (c_beginid,Groupname) 
select * from (select c_id,groupname) as temp 
where not exists (
select c_beginid,groupname from c_group where c_beginid = c_id and groupname = groupname 
) ;


END

我这样称呼它

call insertGroup ('2014-01-01','2015-12-31',100000,'GroupD');

但是它没有插入任何行。 如果c_beginid和groupname不存在,我想插入“ c_group”。

但是当我尝试如下

insert into c_group (c_beginid,Groupname) 
select * from (select 1,'GroupD') as temp 
where not exists (
select c_beginid,groupname from c_group where c_beginid = 1 and groupname = 'GroupD' 
) limit 1 ;

这是工作。

所以我的“ insertGroup” SP出了什么问题。 谁能帮我 ?

谢谢 ,

重命名您的输入参数 ,以便在您意味该参数和列名时清楚地告知数据库引擎。

where startdate = startdate and enddate = enddate and amount = amount 

因为引擎认为您将一列与其自身进行比较,所以它总是对的

暂无
暂无

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

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