Link to home
Start Free TrialLog in
Avatar of Milleniumaire
MilleniumaireFlag for United Kingdom of Great Britain and Northern Ireland

asked on

How do I return multiple rows from an Oracle stored procedure/function to a web service?

I have successfully built an Oracle stored function which takes a single input parameter and returns a single value.  I've then used JDeveloper to create a web service to call this function and successfully got this to run through a browser.

I now need to enhance this simple function to return a record set.  Essentially the function will be passed a couple of values, which it will use to identify one or more rows in a table and I need to return these rows.  I understand there are different ways of coding an Oracle function to do this (ref cursors, arrays etc), but what I need to know is what method to use to ensure the rows are retrieved correctly when called from a web service.  For example, I don't believe ref cursors are a supported data type in a web service.

The web service itself returns its values in xml format, but how do I build the function to return the individual rows from the function such that the web service can return these rows as xml?

I'm new to JDeveloper and web services so please make things simple for me to understand ;-)

Hopefully there is a way to achieve this.
Avatar of POracle
Flag of India image

You can get output of table data in xml form, from procedure.

See this:-

This is just select statement so you can use this in your prosedure.

I don't know JDeveloper. but there may be object or cursor type available to hold rowset from procedure.

you can use ref cursors, I have earlier written procedures which was used by .NET, I am not sure how they used to handle that, however you can explore further.

As @POracle has already mentioned you can achieve it by directly returning the result set in xml format from the procedure. XMLTYPE is a type provided by Oracle which returns XML format data type. The ways of retrieving data in XML format can be done as POracle has highlighted.

However, as you are familiar of using refcursors in Jdeveloper. So by using refcursor you need to use a third party API like CASTOR which converts java objects to XML and vice versa. So, for implementing this you need to follow the steps:
1. Return data through PLSQL procedure by refcursor.
2. Store this data from refcursor into a java object
3. Pass this java object as parameter to CASTOR (or any such) API

you will get back result in XML format. This you can send as XML back to the web service.
Avatar of Milleniumaire


Experts, thanks for your suggestions, however, I have managed to do this by using collections.

I define an object type, then use this to define a table type which I then return in my stored database function.

When JDeveloper is then used to create a web service wrapper around this database function it correctly handles the native collection return type and everything works perfectly without the need for any additional code.
Just to clarify, my database function is written in pure pl/sql, there isn't a line of java code in sight.  JDeveloper generates the necessary code to turn this pl/sql into a web service.
ok thanks for the information. Was thinking otherwise.
Thats good that you get solution.

As I always say, there are multiple way to sort out problems.

still I suggest to select some of answer as assisted solution and if possible post some information about solution you got . It will help to evaluate answer in feature by some one else who facing similar problem..
Avatar of Milleniumaire
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial