-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Passing Array of String to Stored Procedure
PostPosted: Wed May 10, 2006 1:31 pm 
Newbie

Joined: Wed May 10, 2006 1:15 pm
Posts: 2
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:3.1.3

I need to pass an array of string to a stored procedure. The stored procedure is defined as:

FUNCTION findByIds(idArray ARRAY_TYPE)
RETURN SYS_REFCURSOR IS

rtd_cv SYS_REFCURSOR;
sql_stmt VARCHAR2(1000);
sql_where VARCHAR2(1000);

BEGIN

FOR i IN 1 .. idArray.COUNT LOOP
dbms_output.put_line(idArray(i));
END LOOP;

-- More processing code
RETURN rtd_cv;

END;

The named query is:

<sql-query name="SEARCH_BY_IDS_SP" callable="true">
<return class="com.mycompany.PublicTO"/>
{ ? = call findByIds(:Ids) }
</sql-query>


The test code is:

session = sessionFactory.openSession();
Transaction tx = session.beginTransaction();
Query query = session.getNamedQuery("SEARCH_BY_IDS_SP");
String[] ids = {"123","232","123"};

query.setParameter("Ids", ids);
List list = query.list();

session.clear();
session = null;
tx.commit();

But the above test code throws the following exception:

PLS-00306: wrong number or types of arguments in call to 'FINDBYIDS'
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored




My question is how to bind a array of string to a parameter when calling stored procedure?

Thanks

Sean


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 10, 2006 7:43 pm 
Newbie

Joined: Tue May 31, 2005 11:19 pm
Posts: 11
Location: Brisbane, Australia
There doesn't seem to be a SetParameter style function in IQuery that handles arrays.

There's SetParameterList that can take a ICollection but I'm not sure that would do what you want.

An alternative could be to modify your stored procedure to take in a single string and then pass it a comma-separated list of id values.
The stored procedure could then split this string into an array.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 10, 2006 7:55 pm 
Newbie

Joined: Tue May 31, 2005 11:19 pm
Posts: 11
Location: Brisbane, Australia
Update - looks like Oracle doesn't have a split function of its own. Fortunately, quite a few people have created their own:

http://www.google.com.au/search?q=Oracle+split+function


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.