这个 DB2 游标是一个循环吗?

Is this DB2 cursor a loop?(这个 DB2 游标是一个循环吗?)
本文介绍了这个 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 游标是一个循环吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Execute complex raw SQL query in EF6(在EF6中执行复杂的原始SQL查询)
SSIS: Model design issue causing duplications - can two fact tables be connected?(SSIS:模型设计问题导致重复-两个事实表可以连接吗?)
SQL Server Graph Database - shortest path using multiple edge types(SQL Server图形数据库-使用多种边类型的最短路径)
Invalid column name when using EF Core filtered includes(使用EF核心过滤包括时无效的列名)
How should make faster SQL Server filtering procedure with many parameters(如何让多参数的SQL Server过滤程序更快)
How can I generate an entity–relationship (ER) diagram of a database using Microsoft SQL Server Management Studio?(如何使用Microsoft SQL Server Management Studio生成数据库的实体关系(ER)图?)