Oracle RefCursor Example with Ballerina
We are going to try out a simple example of how to call a stored procedure in Oracle which has a refcursor OUT parameter, with Ballerina programming language.
Following are the prerequisites.
- Have Oracle installed. I used 11g.
- Install Ballerina 0.981.0.
- Copy Oracle driver (ojdbc6.jar) to ${BALLERINA_HOME}/bre/lib/
First, let’s look at the stored procedure.
This stored procedure simply takes in a parameter of NUMBER type and returns a refcursor for the result of a select query called on the following table.
Hope the above stored procedure is simple enough!
Let’s create a table.
Here goes the Ballerina program to call the above mentioned stored procedure and iterate the results and print them to console.
When you run this program as follows,
ballerina run refcursor-sample.bal
You should see a result similar to below. Please note that you should have some data inserted to your table corresponding to the SQL query.
1.0|Jim|Young|217.5
So, that is it!