Showing posts with label Return Object from Procedure. Show all posts
Showing posts with label Return Object from Procedure. Show all posts

Monday, May 28, 2012

OAF Return String Array from Procedure

One of the issue we face in OAF is how to get Object from a Procedure. In this post we'll get String Array from Procedure.

Create a VARRAY in PlSql

CREATE OR REPLACE TYPE  STR_ARRAY IS VARRAY(100) OF VARCHAR2(50);

Java code
//setting out parameter
OADBTransaction transaction = getOADBTransaction();
try{
OracleCallableStatement cst = (OracleCallableStatement)transaction.createCallableStatement("begin apps.returnArray(:1,:2);end;",1);

cst.registerOutParameter(2, Types.ARRAY, "APPS.STR_ARRAY");
cst.setString(1,"Hello");
cst.execute();
//returning array type variable
java.sql.Array arr = (java.sql.Array)cst.getObject(2);
//Reading Array
      if (arr != null) {
        String[] strArray = (String[])arr.getArray();
        for (int i = 0; i < strArray.length; i++)
          System.out.println("array at "+i+":"+strArray[i]);
      }
}catch(SQLException ex){
System.out.println(ex);
}