I have a function some_func() that returns refcursor
:
CREATE OR REPLACE FUNCTION some_func() RETURNS refcursor AS (...)
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());
What is the equivalent of that construction on PosgreSQL?
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.
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>";
The cursor name is returned from the function as the refcursor
result, so you can get it from there.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With