oracle存储过程 游标

oracle存储过程 游标 如何在oracle存储过程中返回游标?

如何在oracle存储过程中返回游标?

如何在oracle存储过程中返回游标?

有两种方法,:。一个是声明系统光标,一个是声明自定义光标,然后操作是一样的。参数类型是in out或out (1)来声明个人系统光标。(推荐)创建或替换p _ temp _ procedure(Cur _ Argout sys _ Ref cursor-method 1)begin open Cur _ arg for select * From tablename end,declare Cur _ calling sys _ Ref cursor begin p _ temp _ procedure(Cur _ calling)被调用。-所以这个游标在cur _ calling循环中有一个rec _ next的值...end loop end (2)在头中声明一个swim table类型,然后调用者声明一个这种类型的游标变量,并将其传递给返回游标的存储过程,即存储过程输出的结果集。这种方法很麻烦。光标类型可以 不能像索引表一样使用create或replace type方法创建,所以它们只能在包中声明,需要使用/来执行。以后的存储过程将识别这种游标类型。(不推荐,但建议通过这种了解和认识。毕竟有它的道理)-定义全局变量Create or replace package pkg _ package为type _ cursor is ref cursor type _ record is record(TEST 01 varchar 2(32),test02 varchar2(32),TEST 03 varchar 2(32))end/-Create or replace procedure p _ temp _ procedure(cur _ out _ argout pkg _ package .type _ cursor)返回光标。is begin open cur _ out _ arg for select * from test end/-call declare cur _ out _ arg pkg _ package . type _ cursor rec _ arg pkg _ package . type _ record begin p _ temp _ procedure(cur _ out _ arg)fetch cur _ out _ arg into rec _ arg DBMS _ output . put _ line(rec _ arg . test01)DBMS _ output . put _ line(rec _ arg . test02)DBMS _ output . put _ line(rec _ arg . test03)end