< Prev - Examples - Next >

Typed Reference Cursor

This is the easiest way to open a select cursor and receive a list of structured data from the database.

Example Description

Important Notes !

PL/SQL Package Specification : TYPED_REF_CURSOR
create or replace package typed_ref_cursor

-- this type of record will create a transfer object
type rec_product_version_status is record (
  product   varchar2(100),
  version   varchar2(100),
  status    varchar2(100)

-- this typed ref cursor represents a list of transfer objects
type c_product_version_status is ref cursor return rec_product_version_status;

function get_product_version_status return c_product_version_status;

end typed_ref_cursor;
PL/SQL Package Specification : TYPED_REF_CURSOR
create or replace package body typed_ref_cursor

function get_product_version_status return c_product_version_status
  c c_product_version_status;
  open c for
    select  trim(product),
      from  product_component_version;
  return c;
end get_product_version_status;

end typed_ref_cursor;
Java Calling Class : TypedRefCursor.java
package plsql_workbench_examples;

import java.util.List;

import factory.ExamplesRPCFactory;
import service.TypedRefCursorService;
import transferobject.TypedRefCursorTO;

public class TypedRefCursor {
  public static void main(String[] args) {
    try {
      // get the service
      TypedRefCursorService service = ExamplesRPCFactory.getTypedRefCursorService();

      // call the stored procedure and receive a list as result
      List<TypedRefCursorTO.RecProductVersionStatus> infoList = service.getProductVersionStatus(0);

      // print information
      for (TypedRefCursorTO.RecProductVersionStatus info : infoList) {
        System.out.println(String.format("%-40s  %s  %s", info.product, info.version, info.status));
    catch (Exception e) {