Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1102509
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T01:11:50+00:00 2026-05-17T01:11:50+00:00

I need to pass an array of objects to a PL-SQL function My ORACLE

  • 0

I need to pass an array of objects to a PL-SQL function

My ORACLE code:

CREATE OR REPLACE
TYPE
        uu.ITEMTAB AS TABLE OF ITEMREC; 
/

CREATE OR REPLACE
TYPE
        uu.ITEMREC AS OBJECT (ID NUMBER,
                               NAME VARCHAR2(30)) 
/

Java class

public class ITEMREC {

    private int ID;
    private String NAME;

    public ITEMREC(int iD, String nAME) {
        super();
        ID = iD;
        NAME = nAME;
    }
    public int getID() {
        return ID;
    }
    public void setID(int iD) {
        ID = iD;
    }
    public String getNAME() {
        return NAME;
    }
    public void setNAME(String nAME) {
        NAME = nAME;
    }
}

Java code:

import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Types;

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

public class Testna {

    public static void main(String args[]) throws java.io.IOException, SQLException, ClassNotFoundException
    {

        ITEMREC[] myA = new ITEMREC[1];
        myA[0] = new ITEMREC(1, "BOB");

        Class.forName("oracle.jdbc.driver.OracleDriver");
        Connection con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:ORCL","uu","uu");

        ArrayDescriptor desc= ArrayDescriptor.createDescriptor("ITEMTAB", con);  
        ARRAY array = new ARRAY(desc, con, myA);

        System.out.println("Connection created..............");
        String call = "{ ? = call mainpackage.fgetText(?) }";
        CallableStatement cstmt = con.prepareCall(call);
        cstmt.setQueryTimeout(1800);
        cstmt.registerOutParameter(1, Types.VARCHAR);
        cstmt.setArray(2, array);
        cstmt.executeUpdate();
        String val = cstmt.getString(1);
        cstmt.close();
        con.close();
        System.out.println(val);
    }   
}

Note: here I have only one object, as this is just for test.

The new error I get is at:

ARRAY array = new ARRAY(desc, con, myA);

Exception in thread "main" java.sql.SQLException: Fail to convert to internal representation:

UPDATED:
I have updated my code,

Thanx @Codo

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T01:11:50+00:00Added an answer on May 17, 2026 at 1:11 am

    It’s slightly more complicated than that. First, you need an array type in Oracle. It must be global, i.e. not defined with an PL/SQL package.

    create or replace type NUM_ARRAY as table of number;
    

    Then you need to create an Oracle specific array in Java:

    int intArray[] = { 1,2,3,4,5,6 };
    
    ArrayDescriptor desc= ArrayDescriptor.createDescriptor("NUM_ARRAY", con);  
    ARRAY array = new ARRAY(desc, con, intArray);
    

    This can now be passed to the stored procedure:

    OraclePreparedStatement stmt =
      (OraclePreparedStatement)conn.prepareStatement("begin pkg.proc(:x); end;");
    ps.setARRAY( 1, array_to_pass );  
    ps.execute();
    

    I’m not quite sure how important it is to use the Oracle specific classes from the oracle.jdbc package. But it’s certainly not possible to work with pure JDBC.

    If you provide more information about your array type (both on the Java and the Oracle side) as well as the signature of the PL/SQL procedure, I could give you more specific advice.

    Updated:

    Obviously, you’re not trying to pass an array but a table. I’ve never done that and I don’t know whether it’s possible or not.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to create a large two dimensional array of objects. I've read some
I have an application in which I need to pass an array from C#
I need to pass a simple Javascript array to my wcf ajax webservice: var
Possible Duplicate: when do we need to pass the size of array as a
I need to pass Cursor object to another activity, what is the best way
I have a vector called actorVector which stores an array of objects of type
I want to pass an array of custom objects to the view layer to
I need to get three objects out of a function, my instinct is to
I have an array of objects in javascript and I know that I need
I believe it's possible to pass an array of DOM objects to jQuery's selector

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.