1 CREATE PROCEDURE AddFriend(
2 in myid char(32),
3 in friendid char(32),
4 out sRet varchar(30) character set utf8
5 )
6 BEGIN
7 declare icount int default 0;
8 select count(*) into icount from UserFriendInfo where FriendID=friendid and UserID=myid;
9 if icount >0 then
10 set sRet ='好友已经存在';
11 else
12 insert into UserFriendInfo (UserID, FriendID) values (myid, friendid);
13 set sRet = '';
14 end if;
15 END
我调用这个存储过程时,第8行判断是否已经存在内容,但是第8返回总是大于0,即总是表中已经存在这个内容,不知道为什么
2 in myid char(32),
3 in friendid char(32),
4 out sRet varchar(30) character set utf8
5 )
6 BEGIN
7 declare icount int default 0;
8 select count(*) into icount from UserFriendInfo where FriendID=friendid and UserID=myid;
9 if icount >0 then
10 set sRet ='好友已经存在';
11 else
12 insert into UserFriendInfo (UserID, FriendID) values (myid, friendid);
13 set sRet = '';
14 end if;
15 END
我调用这个存储过程时,第8行判断是否已经存在内容,但是第8返回总是大于0,即总是表中已经存在这个内容,不知道为什么
单独执行
select count(*) into icount from UserFriendInfo where FriendID=friendid and UserID=myid;
有无结果
select count(*) into icount from UserFriendInfo where FriendID=friendid and UserID=myid;
结果正确,但是放到存储过程中,就不正确了
2 in myid char(32), // 这两个参数怎么是Char 呢?
3 in friendid char(32), // 这两个参数怎么是Char 呢?
4 out sRet varchar(30) character set utf8
5 )
修改上面内容再试试。我只找到这个问题。
5楼,为什么不能是char
6楼,我在存储过程中返回了count(*)的值,返回1,不是null
还有什么原因呢