日期:2014-05-17  浏览次数:20872 次

入门级问题ref

我们经常用到这个CREATE OR REPLACE PACKAGE asdf AS type report_row_type is ref cursor 谁能帮我具体解释一下ref的具体含义 和 用法 先谢谢了

------解决方案--------------------
在这里ref coursor是一起定义一个变量类型。不能分开的。
官方解释如下:
Support for Oracle REF CURSOR Types
Oracle PL/SQL and the Oracle SQLJ implementation support the use of cursor variables that represent database cursors.

Overview of REF CURSOR Types

Cursor variables are functionally equivalent to JDBC result sets, essentially encapsulating the results of a query. A cursor variable is often referred to as a REF CURSOR, but REF CURSOR itself is a type specifier, and not a type name. Instead, named REF CURSOR types must be specified. The following example shows a REF CURSOR type specification:

TYPE EmpCurType IS REF CURSOR;

Stored procedures and stored functions can return parameters of Oracle REF CURSOR types. You must use PL/SQL to return a REF CURSOR parameter. You cannot accomplish this using SQL alone. A PL/SQL stored procedure or function can declare a variable of some named REF CURSOR type, execute a SELECT statement, and return the results in the REF CURSOR variable.

See Also:

Oracle Database PL/SQL User's Guide and Reference
REF CURSOR Types in SQLJ

In the Oracle SQLJ implementation, a REF CURSOR type can be mapped to iterator columns or host variables of any iterator class type or of the java.sql.ResultSet type, but host variables can be OUT only. Support for REF CURSOR types can be summarized as follows:

As result expressions for stored function returns

As output host expressions for stored procedure or function output parameters

As output host expressions in INTO-lists

As iterator columns

You can use the SQL CURSOR operator for a nested SELECT within an outer SELECT statement. This is how you can write a REF CURSOR object to an iterator column or ResultSet column in an iterator, or write a REF CURSOR object to an iterator host variable or ResultSet host variable in an INTO-list.



引用楼主 horizonlyhw 的帖子:

我们经常用到这个CREATE OR REPLACE PACKAGE asdf AS type report_row_type is ref cursor 谁能帮我具体解释一下ref的具体含义 和 用法 先谢谢了

------解决方案--------------------
游标分为以下两大类:
1.静态游标:分为显式游标和隐式游标。
2.REF游标: 是一种引用类型,类似于指针。

REF游标就是楼主所指的ref cursor,REF其实就相当于一个标识符,将游标标识为动态的

REF CURSOR游标:又称为动态游标,在运行的时候才能确定游标使用的查询。
REF CURSOR分为两类:
1.强类型(限制)REF CURSOR,规定返回类型 
2.弱类型(非限制)REF CURSOR,不规定返回类型,可以获取任何结果集。

1.弱类型语法:
Declare
 Type refcur_t is ref cursor;
Begin
Null;
End;

2.强类型语法:
Declare
 Type emp_refcur_t is ref cursor return f%rowtype;
Begin
Null;
End
------解决方案--------------------
探讨
游标分为以下两大类:
1.静态游标:分为显式游标和隐式游标。
2.REF游标: 是一种引用类型,类似于指针。

REF游标就是楼主所指的ref cursor,REF其实就相当于一个标识符,将游标标识为动态的

REF CURSOR游标:又称为动态游标,在运行的时候才能确定游标使用的查询。
REF CURSOR分为两类:
1.强类型(限制)REF CURSOR,规定返回类型
2.弱类型(非限制)REF CURSOR,不规定返回类型,可以获取任何结果集。

1.弱类型语法…