Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to get Nested table from function

KarkiDec 21 2013 — edited Dec 23 2013

Hi Friends,

In a package I created a Varchar2 nested table type name EmployeeCodeList.

Then I created a function whose return type is EmployeeCodeList. However I am not getting how will get values from this function?

TYPE EmployeeCodeList IS TABLE OF VARCHAR2(30);

FUNCTION GenerateRandomEcF( Ec_length NUMBER, NumberOfEmp NUMBER )

<<function code>>

RETURN v_RandomEmpCodes;

END GenerateRandomEcF;

PROCEDURE GenerateEmpFile( NumberOfEmp NUMBER, Start_SN NUMBER, EmpValue NUMBER, HireDate VARCHAR2, EmpGroup VARCHAR2, Ec_length NUMBER) IS

v_Filename VARCHAR2(40);

v_EmployeeCodes EmployeeCodeList;

v_EmpBatchF UTL_FILE.FILE_TYPE;

BEGIN

v_Filename := 'EMPLOYEE_BATCH_'||TO_CHAR(SYSTIMESTAMP, 'YYYYMMDD_HHMISS')||'.DAT';

v_EmployeeCodes := EmployeeCodeList(NumberOfEmp);

v_EmployeeCodes := SELECT * FROM TABLE(GenerateRandomAcF(Ac_length, NumberOfVoucher));

   v_EmpBatchF := UTL_FILE.FOPEN('EXT_VOUCHER_DIR', v_Filename, 'W');

  IF UTL_FILE.IS_OPEN(v_EmpBatchF) THEN

  FOR i IN 1..NumberOfVoucher LOOP

  UTL_FILE.PUT_LINE(v_EmpBatchF, v_EmployeeCodes(i)||','||Start_SN+(i-1)||','||EmpValue||','||HireDate||','||EmpGroup );

  END LOOP;

  END IF;

END GenerateEmpFile;

How the above highlighted line/code should be written so that I can get value of function in a variable of same nested table type.

This post has been answered by Partha Sarathy S on Dec 22 2013
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 20 2014
Added on Dec 21 2013
14 comments
4,688 views