1
FUNCTION default_refcursor
  RETURN SYS_REFCURSOR
AS
  v_refcursor SYS_REFCURSOR;
BEGIN
   OPEN v_refcursor FOR
       SELECT * FROM DUAL WHERE 1 = 2;
   RETURN v_refcursor;
END default_refcursor;

the above is cursor from oracle which I have to convert into PostgreSQL (below)

CREATE OR REPLACE FUNCTION prod.common_func_sql$default_refcursor()
RETURNS REFCURSOR
AS
$BODY$
DECLARE
    v_refcursor REFCURSOR;
    v_refcursor$ATTRIBUTES aws_oracle_data.TCursorAttributes := ROW (FALSE, NULL, NULL, NULL);
BEGIN
    v_refcursor := NULL;
    OPEN v_refcursor FOR
           Select 1 where 1=2 ;
    v_refcursor$ATTRIBUTES := ROW (TRUE, 0, NULL, NULL);
    RETURN v_refcursor;
END;
$BODY$
LANGUAGE  plpgsql;

I am getting an error as <unnamed portal 1>. Can anyone highlight what changes are needed, please? The code mentioned in lower section is not working can someone give suggestions?

1 Answers1

0

That's not an error, it is the name PostgreSQL chose for the cursor. If you want a different one, change the line

v_refcursor := NULL;

to

v_refcursor := 'mycursor';
Laurenz Albe
  • 209,280
  • 17
  • 206
  • 263