Skip Headers

Oracle Reports Building Reports
10g (9.0.4)

Part Number B10602-01
Go To Documentation Library
Home
Go To Table Of Contents
Contents
Go To Index
Index

Go to previous page Go to next page

38
Building a Paper Report with Ref Cursors

Figure 38-1 Ref cursor report output

Text description of orbrref_66.gif follows.

Text description of the illustration orbrref_66.gif

Reports Builder enables you to easily manage your queries by use of ref cursors. By using a ref cursor, which is a PL/SQL cursor datatype, you can reference a cursor from within a PL/SQL query. For example, if you already have numerous queries built and you want to reuse those queries in your reports, you can simply use a ref cursor in your report data model to access those queries.

In this chapter, you will learn how to use Reports Builder's features for using ref cursors. To build this paper report, you will use the Data Model view to create a multiquery data model, and then use the Report Wizard to create the report layout. You will make fairly extensive manual refinements in the Data Model view.

About ref cursor queries

A ref cursor is a PL/SQL datatype that you can use in a query to fetch data. Each ref cursor query is associated with a PL/SQL function that returns a strongly typed ref cursor. The PL/SQL function must ensure that the ref cursor is opened and associated with a SELECT statement that has a SELECT list that matches the ref cursor type. You base a query on a ref cursor when you want to:

Furthermore, if you use a stored program unit to implement ref cursors, you receive the added benefits that go along with storing program units in the Oracle database.

The following figure shows that you create a report with the SELECT statement in the ref cursor query of the report. It also shows that you can store the SELECT statement in a package in the database. Then, from the report, you can call the package from the database allowing you to reuse the package in many reports.

Figure 38-2 Overview of the ref cursor example

Text description of refcurs.gif follows.

Text description of the illustration refcurs.gif

Example Scenario

In this example, you will create a detailed report showing information about employees and the job position they hold in each department.

Table 38-1 Features demonstrated in this example
Feature Location

Create package specs that define ref cursors.

Section 38.2, "Define a ref cursor type"

Create ref cursor queries that will use the ref cursors.

Section 38.3, "Create a ref cursor query"

Rename objects in the data model so that they have more meaningful names.

Section 38.4, "Refine the data model"

Create group-to-group data links between ref cursor queries to create relationships between them.

Section 38.5, "Create links between ref cursor queries"

Create summaries that better describe the data.

Section 38.6, "Add summary columns"

Use the Report Wizard to create a report layout.

Section 38.7, "Create a layout"

Move the SELECT statements used by the ref cursor queries from the report and into packages that define the ref cursor types.

Section 38.8, "Move the SELECT statement into a package"

Move the packages into a PL/SQL library so that other reports can share the code.

Section 38.9, "Move the packages into a library"

38.1 Prerequisites for this example

To build the examples in this manual, you must have the example files we've provided. If you haven't already done so, you can download the files you'll need to complete this example from the Oracle Technology network and install them on your machine.

To download and install the example files:

  1. Go to the Oracle Technology Network Web site (http://otn.oracle.com/product/reports/).

  2. Click Getting Started with Oracle Reports.

  3. Click Index, then find the "Building a Paper Report with Ref Cursors" example.

  4. Download the file refcursor.zip into a temporary directory on your machine (e.g., d:\temp).

  5. Unzip the contents of the file, maintaining the directory structure, into an examples directory on your machine (e.g., d:\orawin90\examples).

    This zip file contains the following files:

    Table 38-2 Files necessary for building this sample report using ref cursors
    File Description

    Examples\RefCursor\result\ref_emp*.rdf

    The different stages of the RDF. You can refer to these files as you complete each section of this chapter. The file ref_emp68.rdf is the final report.

    Examples\RefCursor\scripts\refcursor_code.txt

    The PL/SQL code you will write in this chapter. You can use this file as a reference point to make sure your code is accurate, or you can simply cut and paste from this file into Reports Builder.

38.1.1 Access to the sample Human Resources schema

If you don't know if you have access to the sample Human Resources schema provided with the Oracle9i database, contact your database administrator.

38.2 Define a ref cursor type

To create a ref cursor query, you first create a package spec that defines the ref cursor. Then you create a query that uses the ref cursor. The steps in this section will help you create package specs that define ref cursors.

To define a ref cursor type:

  1. Launch Reports Builder (or, if already open, choose File > New > Report)

  2. In the Welcome or New Report dialog box, select Build a new report manually, then click OK.

  3. In the Object Navigator, click the Program Units node under your UNTITLED report node.

  4. Click the Create button in the toolbar to display the New Program Unit dialog box.

  5. In the New Program Unit dialog box, type concl_cv in the Name field.

  6. Select Package Spec, then click OK to display the PL/SQL Editor.

  7. In the PL/SQL Editor, use the template to enter the following PL/SQL code:

    PACKAGE concl_cv IS
        type conclass_rec is RECORD 
           (EMPLOYEE_ID NUMBER(6),
         FIRST_NAME VARCHAR2(20),
         LAST_NAME VARCHAR2(25),
         e-mail VARCHAR2(25),
         PHONE_NUMBER VARCHAR2(20),
         HIRE_DATE DATE,
         JOB_ID VARCHAR2(10),
         SALARY NUMBER(8,2),
         DEPARTMENT_ID NUMBER(4));
        type conclass_refcur is REF CURSOR return conclass_rec;
    END;
    


Go to previous page Go to next page
Oracle
Copyright © 2002, 2003 Oracle Corporation.

All Rights Reserved.
Go To Documentation Library
Home
Go To Table Of Contents
Contents
Go To Index
Index