Currently migrating Oracle database to Postgres and I have come across an use case where I am stuck. In Oracle I have a procedure which returns 3 values
- The resultset from a SELECT query (This is an Oracle ref_cursor)
- A message
- A status
This is the procedure in Oracle
CREATE OR REPLACE PROCEDURE ORA_TEST (
I_EMP_ACTIVE IN VARCHAR2,
O_RESULTSET OUT SYS_REFCURSOR
O_MESSAGE OUT VARCHAR2
O_STATUS OUT VARCHAR2)
AS
V_COUNT NUMBER;
BEGIN
SELECT COUNT(*) INTO V_COUNT FROM EMPLOYEE WHERE EMP_ACTIVE=I_EMP_ACTIVE;
IF V_COUNT>0
OPEN O_RESULTSET FOR SELECT * FROM EMPLOYEE WHERE EMP_ACTIVE=I_EMP_ACTIVE;
O_STATUS := 'SUCCESS';
O_MESSAGE := 'Search Results found';
ELSE
O_STATUS := 'FAILURE';
O_MESSAGE := 'No Search Results found';
END IF;
END;
Now when I try to create this Procedure in Postgres as a Function, I can return the resultset as a TABLE or SETOF RECORD, but I am not able to return the O_MESSAGE and O_STATUS along with the resultset.
Please note that I cannot return the resultset using a Postgres ref_cursor (This is because we have some issues accessing ref_cursor from APIs, which is why we return the resultset using TABLE, SETOF RECORD or SETOF TYPE).
If there any way to achieve this type of resultset (with a TABLE as well as 2 varchar columns)?