关于mysql游标取值为空的问题
我的存储过程如下:
delimiter $$
use heidunlog$$
drop procedure if exists sp_test$$
create procedure sp_test()
begin
declare stop integer default 1;
declare name varchar(50);
declare sqlstr text;
declare cur_1 cursor for select name from user;
DECLARE CONTINUE HANDLER FOR not FOUND set stop=0;
open cur_1;
fetch cur_1 into name ;
while stop <>0 do
select name ;
fetch next from cur_1 into name ;
end while;
set name ='';
end$$
delimiter ;
存在的问题是取出来的tablename老是为空,可以明确的是游标有取到记录,因为stop不为0,循环次数与我的记录数一致
更奇怪的是,我如果把游标定义改成declare cur_1 cursor for select min(id) from user就可以取得到值。请问大家,为什么会有这种现象,我现在要取的是记录集中的name
一楼的兄弟,什么意思,能不能说得再明白点
好了,问题解决了,谢谢一楼兄弟的提醒,虽然不是这种方式,但给了灵感,一样给分,
具体修改方法是光标定义时把查询语句的表名起别名,然后再用如下
declare a.cur_1 cursor for select name from user a;
个人估计是版本不同导致网络上很多关于游标的使用方式不可以,
小弟用的是msyql5.1.38
while stop <>0 do
select name ;
fetch cur_1 into name ;
end while;
declare cur
相关问答:
我是用mysql自带的C API
if(mysql_real_connect(&mysql,"125.0.0.108","root","root","home",3306,NULL,0))
{
AfxMessageBox("数据库连接失败") ......
环境:win2003 apache2 resin3 php5 mysql5
mysql错误里出现这个,服务器直接死到那里。
InnoDB: The log sequence number in ibdata files does not match
InnoDB: the log sequence number in the ib_log ......
我用的like模糊查询,比如mysql的name中有“csdn论坛系统”这几个字,如何在 <input>中查询“csdn 系统”也能出来这个“csdn论坛系统”,我现在是查“csdn”或者“系统”都可以。谢谢各位了!不知道我这么表达 ......
在三十讲遇到这样一个问题就是运行代码时出现错误 Fatal error: Call to undefined method mysql::fetch_array() in D:\WWW\news\index.php on line 12
,我把mysql::fetch_array() 改成mysql::fetch_row() 又出现F ......
mysql>create book(
->id varchar(20) not null,g
->
以上是在mysql命令行里的操作
在上面中我在倒数第二行多打了一个字母g然后按了回车键,请问从倒数第一行怎么 ......