sql 游标只读一次的原因
2016-05-06 19:16
573 查看
今天在用sql的游标的时候,在正确运行的情况下,想再运行一次装一下的时候,发现只能提示 命令已成功生成,并没有得到第一次运行时候的结果。查阅资料以后才知道要在while前面加上一行 fetch。真是被自己蠢哭了,下面看一个简单实例
declare test_cursor4 cursor scroll for select StudyID from [PACS].[dbo].MEDICAL_LOGON open test_cursor4 DECLARE @examid int WHILE @@fetch_status = 0 begin print @examid fetch next from test_cursor4 into @examid end close test_cursor4--关闭游标 deallocate test_cursor4--释放游标
这是原来的代码,测试后会出现上面描述的问题
<pre name="code" class="sql">declare test_cursor4 cursor scroll for select StudyID from [PACS].[dbo].MEDICAL_LOGON open test_cursor4 DECLARE @examid int fetch next from test_cursor4 into @examid WHILE @@fetch_status = 0 begin print @examid fetch next from test_cursor4 into @examid end close test_cursor4--关闭游标 deallocate test_cursor4--释放游标
这是修改后的代码,就是在while之前加上一个 fetch 语句。希望对菜鸟有帮助,因为我也是菜鸟
相关文章推荐
- 数据库字段拼接的问题
- mysql 5.7安装
- Oracle_bond网卡配置
- SQL Server 数据库创建
- mysql存储过程调试学习总结
- 截取字符串,超简单方便
- mssql插件直接执行sql语句取出时间存在时差的问题
- mysql:on duplicate key update与replace into
- 使用Python脚本操作MongoDB的教程
- Redis配置文件redis.conf参数详解
- Redis配置文件redis.conf参数详解
- jsp+mysql实现增加,查看功能
- Redis数据库启动脚本
- Redis数据库启动脚本
- mysql 正斜杠 替换为 反斜杠
- MyBatis Generator实现MySQL分页插件
- mysql语句中日期函数和日期的加减运算
- SQLserver 存储过程执行错误记录到表
- mongodb (1)
- Redis数据库启动脚本