• 全部
  • 问答

mysql 存储过程 into 赋值问题

风.foxwho 2011-10-26 03:31:54
第一个问题

SELECT cdaytime INTO tcdaytime,uid INTO tcuid FROM sz_app_daylogin AS d WHERE uid=iuid;

为什么在一个 SELECT 里面 into 2此赋值就出错
错误信息
-------------
Undeclared variable: uid

第二个问题错误信息
-------------------------
Error Code : 1064
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'begin
update sz_app_daylogin set cnum=cnum+1,cdaytime=tcdaytime where uid=iui' at line 11

以下是关于这个错误的SQL



DELIMITER $$

CREATE
PROCEDURE `login_updatedaylogin`(IN iuid INT,IN tnowtime INT,IN righttime INT)

BEGIN
DECLARE tcdaytime INT DEFAULT 0;
DECLARE tcuid INT DEFAULT 0;

SELECT cdaytime INTO tcdaytime FROM sz_app_daylogin AS d WHERE d.uid=iuid;
SELECT d.uid INTO tcuid FROM sz_app_daylogin AS d WHERE d.uid=iuid;
IF tcuid>0 THEN
BEGIN
IF tcdaytime=righttime
BEGIN
UPDATE sz_app_daylogin SET cnum=cnum+1,cdaytime=tcdaytime WHERE uid=iuid;#连续加1
END;
ELSE
BEGIN
IF tcdaytime=tnowtime
BEGIN
#同一天登录,已经加1,忽略
END;
ELSE
BEGIN
UPDATE sz_app_daylogin SET cnum=0,cdaytime=tcdaytime WHERE uid=iuid;#不连续,清零
END;
END IF;
END
END IF;
END;
ELSE
BEGIN
INSERT INTO sz_app_daylogin(`uid`,`cdaytime`,`cnum`) VALUES (iuid,tnowtime,0);
END;
END IF;
END;


DELIMITER ;
...全文
151 点赞 收藏 3
写回复
3 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
风.foxwho 2011-10-26
汗我知道了。少了THEN


DELIMITER $$

CREATE
PROCEDURE `login_updatedaylogin`(IN iuid INT,IN tnowtime INT,IN righttime INT)

BEGIN
DECLARE tcdaytime INT DEFAULT 0;
DECLARE tcuid INT DEFAULT 0;

SELECT cdaytime,uid INTO tcdaytime,tcuid FROM sz_app_daylogin WHERE uid=iuid;
#select cdaytime into tcdaytime from sz_app_daylogin as d where d.uid=iuid;
#select d.uid into tcuid from sz_app_daylogin as d where d.uid=iuid;
IF tcuid>0 THEN
BEGIN
IF tcdaytime=righttime THEN
BEGIN
UPDATE sz_app_daylogin SET cnum=cnum+1,cdaytime=tcdaytime WHERE uid=iuid;#连续加1
END;
ELSE
BEGIN
IF tcdaytime=tnowtimet THEN
BEGIN
#同一天登录,已经加1,忽略
END;
ELSE
BEGIN
UPDATE sz_app_daylogin SET cnum=0,cdaytime=tcdaytime WHERE uid=iuid;#不连续,清零
END;
END IF;
END
END IF;
END;
ELSE
BEGIN
INSERT INTO sz_app_daylogin(`uid`,`cdaytime`,`cnum`) VALUES (iuid,tnowtime,0);
END;
END IF;
END;


DELIMITER ;
回复
风.foxwho 2011-10-26
第2个问题呢
回复
WWWWA 2011-10-26
SELECT cdaytime,cdaytime INTO tcdaytime,uid INTO tcuid FROM sz_app_daylogin AS d WHERE uid=iuid;
回复
相关推荐
发帖
MySQL
创建于2007-09-28

5.5w+

社区成员

MySQL相关内容讨论专区
申请成为版主
帖子事件
创建了帖子
2011-10-26 03:31
社区公告
暂无公告