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!

Reference to uninitialized collection

739912Mar 23 2010 — edited Mar 23 2010
Hi,

I have created a Java stored procedure as follows:

Type declaration:
CREATE OR REPLACE TYPE transArray AS TABLE OF NUMBER(20)
/
Stored Java Class:
CREATE OR REPLACE AND RESOLVE JAVA SOURCE NAMED testCompTrans AS

import java.math.BigDecimal;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Date;
import java.util.GregorianCalendar;
import java.text.SimpleDateFormat;

import oracle.sql.ARRAY;
import oracle.sql.ArrayDescriptor;

public class testCompTrans {

	public static void callCompTrans(oracle.sql.ARRAY[] returnCompTrans, int memId, int month, 
		int year, int freq, int empWrkgDays, BigDecimal baseSalary, BigDecimal agreedCurrRate,
		String paycycle, String cutoff, String companyCode, String payCurrCode, Date dateJoined){
		
		int arrayLength = 2;
		BigDecimal[] trans = new BigDecimal[arrayLength];
		BigDecimal rate = new BigDecimal("0");
		try{
			prorate = compProrate(memId, month, year, freq, empWrkgDays, baseSalary, agreedCurrRate, paycycle, 
					cutoff, companyCode, payCurrCode, dateJoined);
		
			for(int i=0;i<arrayLength;i++){
				rate = trans;
System.out.println(rate);
}

Connection conn = DriverManager.getConnection("jdbc:default:connection:");
ArrayDescriptor desc = ArrayDescriptor.createDescriptor("transArray",conn);
returnCompTrans[0] = new ARRAY(desc,conn,prorate);

}catch (Exception e){
e.printStackTrace();
}
}
Stored procedure: (from a package)
PROCEDURE SP_COMPTRANS(returnCompTrans OUT transArray, memId IN NUMBER, payMonth IN NUMBER, payYear IN NUMBER, freq IN NUMBER,
empWrkgDays IN NUMBER, baseSalary IN NUMBER, agreedCurrRate IN NUMBER, paycycle IN VARCHAR2, cutOff IN VARCHAR2,
companyCode IN VARCHAR2, payCurrCode IN VARCHAR2, dateJoined IN DATE)
AS LANGUAGE JAVA
NAME 'ori.payroll.OriCompProrate.callCompProrate(oracle.sql.ARRAY[], int, int, int, int, int, java.math.BigDecimal, java.math.BigDecimal, java.lang.String, java.lang.String,
java.lang.String, java.lang.String, java.util.Date)';
I have another stored procedure which will call and process this for each employee - SP_PAYRUN. I just added this:
Initialization:
CREATE OR REPLACE PROCEDURE SP_PAYRUN(EMP_FROM VARCHAR2, EMP_TO VARCHAR2, PAY_YEAR NUMBER, PAY_MONTH NUMBER)
AS
...
....
ARRAYTRANS testArray := testArray(); .....
PG_PAY_RUN.SP_COMPTRANS(ARRAYTRANS, MEMID, PAY_MONTH, PAY_YEAR, FREQ, MTH_WRKG_DAYS, BASE_SALARY, AGREED_CURR_RATE,
PAYCYCLE, 'PY', COMP_CODE, PAY_CURR_CODE, JOINED_DATE);
--I just added this to check the result:
BASE_SALARY := ARRAYTRANS(1);
DBMS_OUTPUT.PUT_LINE(BASE_SALARY);
Then, executed the SP_PAYRUN in SQL* Plus:
set serveroutput on size 20000
execute SP_PAYRUN('2345', '29708161', 2008, 1);
this outputs the base_salary but only after 3 or 4 employees and then I get this error:

BEGIN SP_PAYROLLRUN('2345', '29708161', 2008, 1); END;

*
ERROR at line 1:
ORA-06531: Reference to uninitialized collection
ORA-06512: at "SP_PAYRUN", line 270
ORA-06512: at line 1

I have tried testing my java stored procedure with only one employee and it worked.

The stored procedure should return 21 employees.  What could be the problem with this? Thanks in advance.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 20 2010
Added on Mar 23 2010
4 comments
799 views