Oracle RefCursor Example with Ballerina

Manuri Amaya Perera
Ballerina Swan Lake Tech Blog
1 min readAug 12, 2018

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.

  1. Have Oracle installed. I used 11g.
  2. Install Ballerina 0.981.0.
  3. 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!

--

--

Manuri Amaya Perera
Ballerina Swan Lake Tech Blog

I am an Engineer at WSO2. Currently working in the Ballerina team. Mainly contributing to Ballerina data client area. My GitHub URL: https://github.com/manuri