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 8024307
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T22:49:53+00:00 2026-06-04T22:49:53+00:00

In Java how to get values from a pl/sql function which returns an array.

  • 0

In Java how to get values from a pl/sql function which returns an array.

if my pl/sql function returns array called myArray, in java is it possible to fetch values
from myArray into java objects using callablestatement?

Thanks

Update 1

My Java code where I am calling function, but I am getting exception.

PLS-00306: wrong number or types of arguments in call to 'myfunc'




connection = con.getConnection();
        callablestatement = connection.prepareCall("{call myfunc(?,?,?}");
        callablestatement.setInt(1, param1);
        callablestatement.setInt(2, param2);
        callablestatement.setString(3, param3);
        callablestatement.registerOutParameter(4, Types.ARRAY);
        callablestatement.execute();        
        resultSet = callablestatement.getArray(4).getResultSet();

Update 2

private final String PRODECURE_NAME = "{? = call myfunc(?,?,?)}";

and

connection = con.getConnection();
    callablestatement = connection.prepareCall(PRODECURE_NAME);
    callablestatement.registerOutParameter(1, Types.ARRAY);
    callablestatement.setInt(2, param1);
    callablestatement.setInt(3, param2);
    callablestatement.setString(4, param3);

    callablestatement.execute();

create or replace type dates
       is varray(100) of varchar2(32);

function

CREATE OR REPLACE function myfunc (    
    p_id    IN number,
    p_c_id     IN number,
    p_co_no     IN number

)
    RETURN dates
AS
    myarray contract_dates;
    par1        VARCHAR2 (32);
    par2        VARCHAR2 (32);

Fixed Update 3

connection = con.getConnection();
        callablestatement = 
                connection.prepareCall("begin ? :=myfunc(?,?,?); end;");
        callablestatement.registerOutParameter(1, OracleTypes.ARRAY, "DATES");
        callablestatement.setInt(2, param1);
        callablestatement.setInt(3, param2);
        callablestatement.setString(4, param3);
        callablestatement.execute();
  • 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-06-04T22:49:55+00:00Added an answer on June 4, 2026 at 10:49 pm

    I didn’t do that with ARRAY but it should works. First you must register out parameter of your function. So it can be like this.

    private final String PRODECURE_NAME = "{? = call <ProcedureName>(?,?,?)}";
    
    Connection con = null;
    CallableStatement cs = null;
    
           try {
                con = DAOFactory.getDatabaseConnection();
                cs = con.prepareCall(PRODECURE_NAME);
                cs.registerOutParameter(1, java.sql.Types.ARRAY);
                cs.setYourType(2, <yourData>);
                cs.setYourType(3, <yourData>);
                cs.setYourType(4, <yourData>);
                cs.execute();
                Array arr = cs.getArray(1);
                if (arr != null) {
                   String[] data = (String[]) arr.getArray();
                }
            } 
            catch (SQLException ex) {
                Logger.getLogger(OracleLiekDAO.class.getName()).log(Level.SEVERE, null, ex);
                try {
                    con.rollback();
                }
            }
            finally {
                if (con != null) {
                    try {
                        con.close();
                    } 
                    catch (SQLException ex) {
                        Logger.getLogger(OracleLiekDAO.class.getName()).log(Level.SEVERE, null, ex);
                    }
                }
            }
    

    Try this man and give me then asnwer wether it do or not.

    EDIT:

    These char ? represents one parameter that you will set(it’s named as parametrized).
    So this:

    cs.setYourType(2, <yourData>);
    cs.setYourType(3, <yourData>);
    cs.setYourType(4, <yourData>);
    

    means, that you set your three parameters (?), first parameter of method is column index and second are you data of your specific type.


    EDIT 2:

    So sorry i wrote bad solution, already updated so check code now and try it.

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

Sidebar

Related Questions

I have a function which returns array and I am calling this function from
I'm trying to get the returned value from a java method, but it returns
I have this managed bean which takes two values from database's table import java.io.Serializable;
I tried the below sql query INSERT INTO test.ACT_QUERY values(2139,2,'SELECT ''D'',ORDER_ID from dual'); When
hi i want to retrieve values from SQL database for xml tags using java
How can I get java classes from an xml file? In this situation, I
I want to run Protovis javascript from Java and get the evaluated SVG code.
I currently have a prepared statement in Java which uses the following SQL statement
now i get java.sql.SQLException: No suitable driver found for jdbc:firebirdsql:embedded:f/test.fdb i included jaybird jars
I have a managed bean which gets list of settings and values from database

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.