New Features and Benefits

Building a Report that Includes PLSQL 40-1 40 Building a Report that Includes PLSQL In this chapter, you will learn about reports that include PLSQL. By following the steps in this chapter, you can generate the report output shown in Figure 40–1 . Figure 40–1 PLSQL report output Concepts ■ There are a variety of ways to incorporate PLSQL into your reports. You have already created formula columns that used simple PLSQL expressions to compute their values, and format triggers that used PLSQL to conditionally determine the formatting of mailing labels. Here, you will create external libraries and local functions and procedures. ■ External PLSQL libraries are modules that contain named PLSQL functions and procedures. They may be stored either in the database or in a file, and can be referenced from not only any report, but from other Oracle products. External libraries eliminate the need to re-enter commonly-used PLSQL constructs, whether in reports, forms, or graphs. This, in turn, eliminates the problem of maintaining several versions of the same PLSQL code. ■ Local PLSQL consists of named PLSQL functions and procedures that are saved in a report definition. Local PLSQL may be referenced only by objects within the report for example, group filters, formula columns, format triggers, and so on. However, the usefulness of storing PLSQL in a single location still applies. Data Relationships This report uses one query. You will add a function stored in an external library, a report-level function, two formula columns, and a parameter governing the number of records to display before inserting a space. Layout This report uses the tabular layout style, with minor modifications. 40-2 Oracle Reports Users Guide to Building Reports Example Scenario In this example, you will use an external PLSQL library and PLSQL within a report to modify formatting to add spacing between records, and calculate the total compensation for each employee. You will manually create a query in the Data Model view, then modify the layout of the report in the Paper Layout view. You will create formula columns, a summary column, and a format trigger that uses a summary column and a user parameter. As you build this example report, you will: ■ Create a New PLSQL Library that you will use in this report. ■ Create the Report Definition : ■ Create a query . ■ Create a formula column that calculates bonuses . ■ Create a report-level function that calculates total compensation . ■ Create a second formula column for total compensation . ■ Create the Report Layout Using the Report Block Wizard . ■ Add Vertical Space Between Records : ■ Create a user parameter . ■ Create a summary column that counts the number of records . ■ Modify the layout . ■ Create a format trigger . ■ Run Your Report to Paper . To see a sample PLSQL report, open the examples folder named plsql, then open the Oracle Reports example named plsql.rdf. For details on how to open it, see Accessing the Example Reports in the Preface.

40.1 Prerequisites for This Example

To build the example in this chapter, you must have access to the Human Resources sample schema HR provided with the Oracle Database. If you do not know if you have access to this sample schema, contact your database administrator.

40.2 Create a New PLSQL Library

The steps in this section will show you how to create a new PLSQL library, then create a function that will live in this library. To create the library:

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, choose File New PLSQL Library. A new library displays in the Object Navigator below your report name, under the PLSQL Libraries node.