无论是命运还是运气, 我正在致力于将 DB2 存储过程转换为 SQL Server 存储过程。
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;
问题
- Am I correct in my assumption2 that this is only a
select
statement actually returning a result set when the cursor is opened?
- If an error has occurred before the cursor is opened3, will the SP return a blank result set for
entity_cursor
?
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.
对于你的第一个问题:正如评论中提到的,打开游标不会产生结果集,而只是一个(指向)结构,允许您使用FETCH
声明或同等内容。此外,当您开始获取记录时,结果集甚至可能没有完全具体化——这取决于实际的查询和各种游标选项。
对于第二个问题:如果您的存储过程在打开游标之前正常或以其他方式返回,则其调用者将获得未初始化的游标结构(当您尝试访问它时将导致异常)而不是空结果集。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)