在Oracle中,open-for和带参数打开游标有什么区别?
这两段代码有什么区别?
TYPE t_my_cursor IS REF CURSOR;
v_my_cursor t_my_cursor;
OPEN v_my_cursor FOR SELECT SomeTableID
FROM MYSCHEMA.SOMETABLE
WHERE SomeTableField = p_parameter;
而且......
CURSOR v_my_cur(p_parameter VARCHAR2) IS
SELECT SomeTableID
FROM MYSCHEMA.SOMETABLE
WHERE SomeTableField = p_parameter;
OPEN presf_cur(p_subscriber_id);
它们似乎都有效。它们是相同的还是有一些我应该注意的区别?
What is the difference between these two pieces of code?
TYPE t_my_cursor IS REF CURSOR;
v_my_cursor t_my_cursor;
OPEN v_my_cursor FOR SELECT SomeTableID
FROM MYSCHEMA.SOMETABLE
WHERE SomeTableField = p_parameter;
And...
CURSOR v_my_cur(p_parameter VARCHAR2) IS
SELECT SomeTableID
FROM MYSCHEMA.SOMETABLE
WHERE SomeTableField = p_parameter;
OPEN presf_cur(p_subscriber_id);
They both seem to work. Are they the same or is there some difference I should be aware of?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
第二个示例是显式游标,并且它是静态的。也就是说,它是与一条 SQL 语句关联的变量。有一个隐式等价物...
第一个示例是引用游标,它是指向 SQL 语句的指针,因此可以是动态的。例如,我们可以像这样扩展该示例:
甚至:
因此,使用引用游标可以让我们更好地控制最终执行的 SQL 语句。另一个区别是,因为引用游标是一个指针,所以它可以在程序之间传递。这对于将数据从 PL/SQL 传递到其他语言(例如 JDBC 结果集)非常有用。
The second example is an explicit cursor, and it is static. That is, it is a variable associated with one SQL statement. There is a implicit equivalent...
The first example is a ref cursor, which is a pointer to a SQL statement and so can be dynamic. For instance we can extend that example like this:
Or even:
So using a ref cursor gives us a lot more control over the final SQL statement which gets executed. The other difference is that, because a ref cursor is a pointer it can be passed between programs. This is very useful for passing data from PL/SQL to other languages, for instance a JDBC result set.
API(一个包),您可以将您的
游标定义位于
规范水平并给出
客户端程序员有更好的感觉
您的 API 执行什么操作并返回什么
无需意识到
源代码。
可能会与指定的人一起玩得更好
光标。
API (a package) you can place your
cursor definitions at the
specification level and give the
client programmer a better sense of
what your API does and returns
without needing to be aware of the
source code.
will likely play nicer with a named
cursor.