该DB2游标是一个循环吗? [英] Is this DB2 cursor a loop?

查看:63
本文介绍了该DB2游标是一个循环吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过命运或运气,我正在致力于将DB2存储过程转换为SQL Server存储过程.

Through fate or luck, I am working on converting DB2 stored procedures to SQL Server stored procedures.

在DB2中我不能完全理解的一件事是游标 1 .通过查看并阅读一些文档,看来这只是一个选择语句.

One thing I could not completely understand in DB2 is cursors1. By looking at it and reading some documentation, it appears that it is only a select statement.

-- DB2 stored procedure code
declare entity_cursor cursor with return for
select *
from TableName;

...
--a lot more cursors like above, and some other code
...

open entity_cursor;

问题

  1. 我是否根据我的假设 2 纠正了这只是一个 select 语句实际上会在打开游标时返回结果集吗?
  2. 如果在打开光标之前 3 发生错误,SP会为 entity_cursor 返回空白结果集吗?
  1. Am I correct in my assumption2 that this is only a select statement actually returning a result set when the cursor is opened?
  2. If an error has occurred before the cursor is opened3, will the SP return a blank result set for entity_cursor?


1 :我知道SQL Server它们通常用于逐行执行操作.
2 :基于阅读DB2文档以及一些我的知识和才智.
3 :不幸的是,我无法完全测试DB2中的存储过程.


1: I know that SQL Server they are commonly used for performing operations on row-by-row.
2: Based on reading DB2 documentation and a little on my knowledge and intellect.
3: Unfortunately I cannot fully test the stored procedure in DB2.

推荐答案

第一个问题:如注释中所述,打开游标不会产生结果集,而只是允许您访问的结构(指向a)使用 FETCH 语句或等效语句的结果集.此外,当您开始获取记录时,结果集甚至可能无法完全实现-这取决于实际查询和各种游标选项.

To your first question: as mentioned in comments, opening a cursor does not produce a result set, but merely a (pointer to a) structure allowing you to access the result set using the FETCH statement or equivalent. Moreover, the result set may not even be fully materialized when you start fetching records -- this depends on the actual query and various cursor options.

第二个问题:如果您的存储过程正常(或以其他方式返回),在打开游标之前,其调用方将获得未初始化的游标结构(当您尝试访问它时将导致异常),而不是空的结果集

To your second question: if your stored procedure returns, normally or otherwise, before opening the cursor, its caller will get an uninitialized cursor structure (which will cause an exception when you try to access it) and not an empty result set.

这篇关于该DB2游标是一个循环吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆