简体   繁体   English

光标和视图有什么区别?

[英]What is the difference between cursor and view?

What is the difference between cursor and view ? cursorview什么区别? Because none of them store data in the database. 因为它们都不在数据库中存储数据。

A cursor is defined and used within the scope of a stored procedure (it is used with PL/SQL). 在存储过程的范围内定义并使用了游标(它与PL / SQL一起使用)。

On the other hand, a view is a database object (similar to a table), which can be used even outside of stored procedures as well, as in queries (it can be used with both SQL and PL/SQL). 另一方面,视图是一个数据库对象(类似于表),它甚至可以在存储过程之外使用,也可以在查询中使用(可以与SQL和PL / SQL一起使用)。

Reference : 参考

  1. Views on Oracle Database Concepts 关于Oracle数据库概念的观点

  2. Cursors on Oracle Magazine Oracle Magazine上的游标

A view is a pre-defined query which is stored in the database and can be used much like a table. 视图是预定义的查询,存储在数据库中,可以像表一样使用。

A cursor is a data structure which provides access to the rowset returned by a query. 游标是一种数据结构,它提供对查询返回的行集的访问。

Share and enjoy. 分享并享受。

VIEWS are for easy usage like MACROS except materialized Views. VIEWS是容易使用像MACROS除了物化视图。

Materialised views have data stored up in memory. 物化视图将数据存储在内存中。 Where as other views when queried, simply gets replaced with the coressponding definition while executed. 在查询时,与其他视图一样,在执行时只需替换为coressponding定义即可。 And it is available for everyone to query, until they have privilege to access it. 它可供所有人查询,直到他们有权访问它为止。

CURSORS other way is a different thing. CURSORS其他方式是另一回事。 It is pointing to a resultset of somequery available to the creator of it. 它指向它的创建者可以使用的somequery的结果集。 Either a PL/SQL or any other OCI calls. PL/SQL或任何其他OCI调用。

Cursors are handy to set up report data, since the simplest way to make a report is to set up a rather non-normalized table of the data in the appropriate order, and run from there. 游标很容易设置报告数据,因为制作报告的最简单方法是按照适当的顺序设置一个相当不规范的数据表,然后从那里开始运行。

Views are used a lot by developers who don't know whether the end user will have Fox tables or use SQL-server, or whose Fox tables are reaching their limit and might be migrated for size reasons. 开发人员经常使用视图,这些开发人员不知道最终用户是使用Fox表还是使用SQL服务器,或者不知道Fox表是否已达到极限并可能由于大小原因而迁移。 The programming which uses the views (the grid on the form) is the same whether the view is local or remote. 无论视图是本地视图还是远程视图,使用视图(窗体上的网格)的程序都是相同的。 Then, when the data is migrated, the effort to change from local views to remote views is small. 然后,在迁移数据时,从本地视图更改为远程视图的工作量很小。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM