oracle 如何检查引用游标是否从 pl/sql 过程返回数据
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4044395/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to check if a ref cursor returns data from a pl/sql procedure
提问by Martin
I would like to know how to check if a ref cursor returns data.
我想知道如何检查引用游标是否返回数据。
Let's say I have the following code in a PL/SQL package:
假设我在 PL/SQL 包中有以下代码:
type refcursor is ref cursor;
procedure Foo(cursorresult out refcursor) is
begin
open cursorresult for
select *
from table t
inner join t2 on t.id = t2.id
where t.column1 is null;
end;
procedure DoSomeghingIfFooHasResults is
curFoo refcursor;
begin
Foo(curSansOwner);
if curFoo%found then
-- Do something
end if;
end function;
This code is used in a more involved process and the query in Foo is using multiple tables.
此代码用于更复杂的过程,并且 Foo 中的查询使用多个表。
I need the data returned from Foo in an asp.net application, but I also need to do something when Foo finds some data.
我需要在asp.net应用程序中从Foo返回的数据,但是当Foo找到一些数据时我也需要做一些事情。
I want to reuse the query at a few places, but I don't think this would be a good candidate for a view.
我想在几个地方重用查询,但我认为这不是一个很好的视图候选者。
What would be the best way to know if Foo finds something ?
知道 Foo 是否找到某些东西的最佳方法是什么?
Thanks.
谢谢。
回答by Tony Andrews
The only way to know if it has found something is to FETCH from it:
知道它是否找到了某些东西的唯一方法是从中提取:
procedure DoSomeghingIfFooHasResults is
curFoo refcursor;
recFoo mytable%ROWTYPE;
begin
Foo(curFoo);
fetch curFoo into recFoo;
if curFoo%found then
-- Do something
end if;
end function;