MySQL存储过程无法正常工作

时间:2014-12-31 05:16:43

标签: mysql stored-procedures

我是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_group"如果c_beginid和groupname不存在。

但是当我尝试下面的时候

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。谁能帮我 ?

谢谢,

1 个答案:

答案 0 :(得分:2)

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

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

始终为true,因为引擎认为您将列与自身进行比较

相关问题