Enhanced Pie New Graph Types

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. 40-4 Oracle Reports Users Guide to Building Reports The objects in your Object Navigator should now look something like this: Figure 40–2 Object Navigator

18. Save your report as plsqlreport_your_initials.rdf.

40.3 Create the Report Definition

The steps in this section will show you how to create the query and the formula columns that will define the report and call the code in the bonus.pll external PLSQL library you created. We recommend that you create the objects in the order described, as some of the formula columns depend on the functions, and so on.

40.3.1 Create a query

The steps in this section will show you how to create the query that will retrieve the data necessary for this report. To create the query:

1. In the Object Navigator, double-click the view icon next to the Data Model node

to display the Data Model view.

2. In the Data Model view, choose Insert Query to display the Data Wizard.

3. If the Welcome page displays, click Next.

4. On the Query page, leave the default query name, then click Next.

5. On the Data Source page, select SQL Query, then click Next.

Note: If you attach a library whose name also includes a path, Reports Builder will inform you that the path names are not portable, and will give you the option of deleting the path. If you choose to continue using a path specification, Reports Builder will only look in that specific location for the library. So, if you move the library, Reports Builder will not be able to find it. If you delete the path, Reports Builder will use a standard search path to locate the library if it is moved. Building a Report that Includes PLSQL 40-5

6. On the Data page, enter the following SELECT statement in the Data Source

definition field: SELECT FIRST_NAME, LAST_NAME, JOB_ID, SALARY,COMMISSION_PCT FROM EMPLOYEES ORDER BY LAST_NAME

7. Click Next.

8. On the Groups page, click Next.

9. Click Finish to display your first query in the Data Model view. It should look

something like this: Figure 40–3 Data Model view of the PLSQL report 10. Save your report.

40.3.2 Create a formula column that calculates bonuses

The steps in this section will show you how to create a formula column that will calculate the salary bonus for each employee using the PLSQL function. Note: You can enter this query in any of the following ways: ■ Copy and paste the code from the provided text file called plsql_code.txt into the Data Source definition field. ■ Click Query Builder to build the query without entering any code manually. ■ Type the code in the Data Source definition field. Note: If you are not already connected to a database, you will be prompted to connect to the database when you click Query Builder or Next. Ensure that you connect to a database that has the appropriate schema for this example. Section 40.1, Prerequisites for This Example describes the sample schema requirements for this example.