-->
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: How to write scalar when no of columns are not fixed.
PostPosted: Mon Jan 24, 2011 9:45 am 
Newbie

Joined: Mon Jan 24, 2011 9:35 am
Posts: 2
We are facing an issue while executing a stored procedure in hibernate.

Issue:
We have a stored procedure named “GET_OFFER_CATEGORIES_PRO” which takes “country” as an input argument and returns a ref cursor which contains categories and importers.
The problem is that for different countries passed, the number of columns which the SP returns will vary (because no of importers for each country varies).
So I am not able to map exact number of column names in mapping xml file.
For example - for certain country if it returns values for two importers, for certain other country it will return values for a three importers.
So we are confused how to write it in mapping xml file.

<sql-query name="getMoreMktInfo" callable="true">
<return-scalar column="catagory" type="java.lang.String"/>
<return-scalar column="imp1" type="java.lang.String"/>
<return-scalar column="imp2" type="java.lang.String"/>
<return-scalar column="imp3" type="java.lang.String"/>

{call GET_OFFER_CATEGORIES_PRO(?,:country)}
</sql-query>

If SP returns values for 3 importers the above snippet will work fine, but if only two importers are there then a SQL exception is thrown (invalid column name).

The stored procedure specification is:
create or replace PROCEDURE Get_offer_categories_pro (
REF_CURSOR OUT SYS_REFCURSOR,
I_COUNTRY_ID IN OFFER_OBJECT.COUNTRY_ID%TYPE)

Please help.


Top
 Profile  
 
 Post subject: Re: How to write scalar when no of columns are not fixed.
PostPosted: Mon Jan 24, 2011 10:27 am 
Beginner
Beginner

Joined: Thu Feb 08, 2007 10:40 am
Posts: 46
Can you modify the stored procedure, so that it always returns three columns, where the first column holds the category name, the second one holds the name of the importer and the third column holds the value for that category/importer combination?

If for example your current version of the stored procedure returns four columns and 2 lines like this:
Code:
catagory | imp1         | imp2         | imp3   
---------+--------------+--------------+--------------
cat1     | val4imp1cat1 | val4imp2cat1 | val4imp3cat1
cat2     | val4imp1cat2 | val2imp2cat2 | val4imp3cat2

The new version would now return three columns and six lines:
Code:
category | impname | value
---------+---------+--------------
cat1     | imp1    | val4imp1cat1
cat1     | imp2    | val4imp2cat1
cat1     | imp3    | val4imp3cat1
cat2     | imp1    | val4imp1cat2
cat2     | imp2    | val4imp2cat2
cat2     | imp3    | val4imp3cat2
That way, your stored procedure no longer returns a variable number of columns.


Top
 Profile  
 
 Post subject: Re: How to write scalar when no of columns are not fixed.
PostPosted: Tue Jan 25, 2011 6:47 am 
Newbie

Joined: Mon Jan 24, 2011 9:35 am
Posts: 2
Thanks etwcn for the quick help.

Provided suggestion will make the column numbers fixed.
But business department needs that functionality only :(

If any one faced this issue earlier, Please guide.


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.