您的位置:首页 > 数据库 > MySQL

Mysql Procedure 使用concat申城动态字段、存储查询结果到临时变量

2013-06-24 18:38 369 查看
1.declare t_hasSigned tinyint(3);

set t_hasSigned = 0;

set @sqlStr = concat('select count(playerId) from tb_sign where playerId =',iPlayerId , ' and day', iSignDate, '=1 into @t_hasSigned' );

prepare addSqlStr from @sqlStr;

execute addSqlStr;

DEALLOCATE PREPARE addSqlStr;

SET tt_hasSigned = @t_hasSigned;

看这个例子,想把查询结果存到t_hasSigned中,但是系统报错,所以要存到@t_hasSIgned中,然后调用deallocate prepare 和 set 把值取出来。

2. set @sqlStr = concat('update tb_sign set day', iSignDate, '=', 1, ',lastSignDate=',concat('\'', year(now()), '-', month(now()), '-', iSignDate, '\''), ',accuSignCount=accuSignCount+1', ' where playerId
= ' ,iPlayerId, ';');

这个例子中注意的是accuSignCount+1这个点,如果你把它当做已知变量,想用它的值就错了,所以要写到字符串里面,而不调用它的值。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: