Thursday, March 8, 2018

PL/SQL - RETURN MULTIPLE VALUES FROM THE FUNCTION

--- CREATE OBJECT-TYPE

   CREATE TYPE HZ_PARTY_OBJ IS OBJECT (PARTY_ID NUMBER,PARTY_NUMBER VARCHAR2(30),PARTY_NAME VARCHAR2(360));
 
--- TABLE TYPE

   CREATE TYPE HZ_PARTY_TAB IS TABLE OF HZ_PARTIES_OBJ;
 
--- CREATE FUNCTION

CREATE OR REPLACE FUNCTION GET_PARTIES
  RETURN HZ_PARTY_TAB
   IS
   L_HZ_PARTY_TAB  := HZ_PARTY_TAB();
    N INTEGER := 0;
BEGIN 
   FOR R IN (SELECT PARTY_ID,PARTY_NUMBER,PARTY_NAME FROM HZ_PARTIES)
   LOOP
      L_HZ_PARTY_TAB.EXTEND;
      N := N +1 ;
      L_HZ_PARTY_TAB(N) := HZ_PARTY_OBJ(R.PARTY_ID,R.PARTY_NUMBER,R.PARTY_NAME);
      END LOOP;
      RETURN L_HZ_PARTY_TAB;
END;

No comments:

Post a Comment