3

I have a Stored procedure which takes 2 input parameter and 6 out. One of the out parameter returns more than one record. Is there any way to declare it as an array hence I don't have to declare a cursor. Here is the code,

CREATE OR REPLACE PROCEDURE SP_GET_USER_DETAILS 
(
  P_ID IN OUT VARCHAR2 
, P_USER_NAME IN OUT VARCHAR2 
, P_USER_TYPE OUT VARCHAR2 
, P_EMPLOYEE_ID OUT VARCHAR2 
, P_LICENSE_NO OUT VARCHAR2 
, P_PHONE_NO OUT VARCHAR2 
) IS 

BEGIN

  SELECT ACCT.ID, ACCT.USERNAME, ACCT.EMPLOYEE_ID, ACCT.LICENSE_NO, 
  ADDRESS.PHONE_NO INTO P_ID, P_USER_NAME, P_EMPLOYEE_ID, P_LICENSE_NO, P_PHONE_NO
  FROM PROVIDER_ACCT ACCT 
  LEFT OUTER JOIN EMP_ADDRESS ADDRESS ON ACCT.ID=ACCT.ID

END SP_GET_PRISON_USER_DETAILS;

The problem is ADDRESS.PHONE_NO alone returns multiple rows. Is there any way to declare it as an array and get this working ? Thanks in advance.

If its not possible, could you please explain how to do it using a ref cursor ?

3
  • Short answer, no. return a ref cursor. Commented Jan 8, 2016 at 22:46
  • could you please explain how to do it using a ref cursor
    – jijo
    Commented Jan 8, 2016 at 22:51
  • Google "oracle pl/sql ref cursor" and read. Commented Jan 9, 2016 at 2:22

1 Answer 1

3

Use a collection:

CREATE OR REPLACE PROCEDURE SP_GET_USER_DETAILS 
(
  P_ID          IN OUT VARCHAR2 
, P_USER_NAME   IN OUT VARCHAR2 
, P_USER_TYPE   OUT VARCHAR2 
, P_EMPLOYEE_ID OUT VARCHAR2 
, P_LICENSE_NO  OUT VARCHAR2 
, P_PHONE_NO    OUT SYS.ODCIVARCHAR2LIST
)
IS 
BEGIN
  SELECT ID,
         USERNAME,
         EMPLOYEE_ID,
         LICENSE_NO
  INTO   P_ID,
         P_USER_NAME,
         P_EMPLOYEE_ID,
         P_LICENSE_NO
  FROM   PROVIDER_ACCT;

  SELECT ADDRESS.PHONE_NO
  BULK COLLECT INTO P_PHONE_NO
  FROM   PROVIDER_ACCT ACCT 
         LEFT OUTER JOIN EMP_ADDRESS ADDRESS
         ON ACCT.ID = ADDRESS.ID;

END SP_GET_PRISON_USER_DETAILS;
/

Note: you haven't specified a where clause in your question - you probably want to add one in.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.