I have a oracle procedure which return two parameter, 1st is array object type and 2nd is number.
My procedure is :
CREATE OR REPLACE PROCEDURE APPS.xx_push_notification (
p_user_name IN VARCHAR2,
p_hr_type IN VARCHAR2,
p_ret_array OUT NOCOPY XX_WF_SVC_NTF_ARRAY,
p_ret_array_size OUT NOCOPY NUMBER
)
AS
--l_item_type IN VARCHAR2,l_message_names IN VARCHAR2,
l_orig_system VARCHAR2 (4000);
l_orig_system_id NUMBER;
l_ret_array xx_wf_svc_ntf_array;
l_ret_array_size NUMBER;
l_item_type VARCHAR2 (1000);
l_message_names VARCHAR2 (4000);
l_latest_ntf_id NUMBER;
CURSOR cur_hrms (
cur_orig_system VARCHAR2,
cur_orig_system_id NUMBER
)
IS
......................
......................
......................
BEGIN
......................
......................
......................
p_ret_array := xx_wf_svc_ntf_array ();
IF p_hr_type = 'HR_ABSENCES'
THEN
FOR c1_rec IN cur_hrms (l_orig_system, l_orig_system_id)
LOOP
p_ret_array.EXTEND;
p_ret_array (p_ret_array.COUNT) :=
xx_wf_svc_ntf_record (c1_rec.NOTIFICATION_ID,
c1_rec.CONTEXT,
c1_rec.FROM_USER,
c1_rec.TO_USER,
c1_rec.SUBTYPE);
END LOOP;
p_ret_array_size := p_ret_array.COUNT;
END IF;
END;
/
oracle type object :
create or replace type xx_wf_svc_ntf_record is object (NOTIFICATION_ID NUMBER,
CONTEXT VARCHAR2(2000),
FROM_USER VARCHAR2(320),
TO_USER VARCHAR2(320),
SUBJECT VARCHAR2(2000),
SUBTYPE VARCHAR2(32));
/
oracle type array :
create or replace type xx_wf_svc_ntf_array is table of xx_wf_svc_ntf_record ;
/
My java code is :
.......
.......
db = new DBConnectionManager();
conn=db.getConnection();
if(conn!=null)
{
cstmt = conn.prepareCall("{call xx_push_notification(?, ?, ?, ?)}");
cstmt.setString(1, UserName);
cstmt.setString(2, NotificationType);
cstmt.registerOutParameter(3, OracleTypes.ARRAY,typeTableName);
cstmt.registerOutParameter(4, Types.INTEGER);
cstmt.execute();
int newRecord=cstmt.getInt(4);
System.out.println("Total New Record : "+newRecord);
}
.........
.........
I get 2nd out parameter which is return array size. I have many R&D for parsing oracle type array. I got single array parsing which is return by oracle procedure. But I do not know how to parse array oracle type object.
Thanks in advance.
Being an output parameter, your code can get mangled by any connection pool you are using if you try to use Oracle types and classes. I suggest you read it as a plain java.sql.Array
made of instances of java.sql.Struct
.
Maybe you can get it to work by simply doing:
java.sql.Struct records[] =
(java.sql.Struct[]) ((java.sql.Array) cstmt.getObject(3)).getArray()
And then you can simply get the attributes of every Struct
in that array.