Curved Line or Fit To Curve Graph

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. Building a Report that Includes PLSQL 40-3 4. If it is not already expanded, expand the node of the new library to show the two subnodes: Program Units and Attached Libraries.

5. Click the Program Units node, then choose Edit Create.

6. In the New Program Unit dialog box, in the Name field, type BONUS_PAY.

7. Select Function, then click OK to display the PLSQL Editor.

8. In the PLSQL Editor, use the template to enter the following PLSQL code: FUNCTION BONUS_PAYJOB_ID IN CHAR, SAL IN NUMBER, COMM_PCT IN NUMBER RETURN NUMBER IS BEGIN IF JOB_ID = SA_REP THEN RETURN SAL 0.15; ELSE IF SAL COMM_PCT = 500 THEN RETURN SAL + SAL COMM_PCT 0.15; ELSE RETURN SAL + SAL COMM_PCT 0.10; END IF; END IF; END;

9. Click Compile.

10. If there are compilation errors, match your code to the code we have provided either in the example RDF file or in this chapter, then compile it again.

11. Once there are no compilation errors, click Close.

Your new function displays in the Object Navigator.

12. Choose File Save to save your new function.

13. In the Save Library dialog box, type bonus.pll, make sure File System is

selected, then click OK. 14. In the Object Navigator, under the MODULE1 report you have created, click the Attached Libraries node. Be sure to select this node, and not the one under the PLSQL Libraries node.

15. Choose Edit Create.

16. In the Attach Library dialog box, in the Library field, type bonus.pll.

17. When the library name displays in the Library field, click Attach to attach the

library. Note: You can enter this code by copying and pasting it from the provided text file called plsql_code.txt. Note: If you saved bonus.pll to another directory, you can click Browse to find it on your file system. Just make sure you have selected File System before browsing.