如何从PL/pgSQL函数返回的refcursor中选择所有行? [英] How to select all rows from refcursor returned by PL/pgSQL function?

查看:318
本文介绍了如何从PL/pgSQL函数返回的refcursor中选择所有行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个函数some_func()返回refcursor:

I have a function some_func() that returns refcursor:

CREATE OR REPLACE FUNCTION some_func() RETURNS refcursor AS (...)

我想从控制台调用此函数,并从其返回的游标中显示结果集.在Oracle中,我会写:

I want to call this function from console and display the result set from the cursor returned by it. In Oracle I would write:

SELECT * FROM TABLE(some_func());

与PosgreSQL上的构造等效吗?

What is the equivalent of that construction on PosgreSQL?

推荐答案

refcursor由其名称引用,该名称可以自动生成,也可以由您选择. 此页面提供了每个示例.

A refcursor is referred to by its name, either auto-generated or chosen by you. This page of the doc gives an example for each.

要从refcursor获取结果,您必须具有游标的名称.对于生成的名称,其名称类似于<unnamed portal 1>".然后,您可以:

To fetch results from a refcursor you must have the cursor's name. In the case of generated names that'll be something like <unnamed portal 1>". You can then:

FETCH ALL FROM "<unnamed portal 1>";

游标名称是作为refcursor结果从函数返回的,因此您可以从那里获取它.

The cursor name is returned from the function as the refcursor result, so you can get it from there.

这篇关于如何从PL/pgSQL函数返回的refcursor中选择所有行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆