Improving performance using WHERE clauses

4-138 Oracle Reports Users Guide to Building Reports 1. In the Object Navigator, double-click the properties icon for the report to display the Property Inspector.

2. Under the Report node, set the Role Name property as defined by the database

administrator in the database. 3. Optionally, to set a Role Password, double-click the button in the Role Name value field to display the Set Role dialog box. Usage notes ■ The role settings in the report are overridden if you specify a role using the command line with Reports Runtime rwrun. ■ You can set only one role for a report. To set multiple roles, you need to set a role to which the other roles have been granted. See also Section 2.9.1, About database roles

4.16.2 Converting from one format to another

To convert one or more report definitions or PLSQL libraries from one storage format to another: ■ In Oracle Reports Builder, choose Tools File Conversion to display the Convert dialog box. ■ On the command line on Windows, type ORACLE_HOME\bin\rwconverter, followed by the report name and desired arguments.

4.16.3 Improving performance using SQL statements

Performing operations in SQL is faster than performing them in Oracle Reports Builder or PLSQL. The following are the most common cases where using SQL would improve performance: ■ Use a WHERE clause instead of a group filter or format trigger to exclude records. ■ Use the SUBSTR function to truncate character strings instead of truncating in Oracle Reports Builder. ■ Perform calculations directly in your query rather than in a formula or summary. Rationale: SQL can perform calculations more quickly than a summary or formula. WHERE and SUBSTR can reduce unnecessary fetching because they operate on the data during rather than after data retrieval. Improvements in performance become more noticeable when retrieving thousands of records versus a few records.

4.16.4 Improving performance using WHERE clauses

Consider adding a WHERE clause for the matrix cell query in a multiquery data model. If you are using a multiquery data model and your dimension queries are restricted by a WHERE clause, adding a WHERE clause to the matrix cell query Caution: Do not attempt to set the role in a PLSQL trigger. The PLSQL will not compile. How To... 4-139 ensures that you do not retrieve more records than are necessary. For example, suppose that you had the following queries for your dimensions: Q_Dept SELECT DEPTNO FROM DEPT WHERE DEPTNO 100 Q_Job SELECT DISTINCT JOB FROM EMP WHERE DEPTNO 100 Q_Filler To ensure that your cell query only retrieves the records that are necessary, you would write the following SELECT statement: SELECT DEPTNO, JOB, SUMSAL FROM EMP WHERE DEPTNO IN SELECT DEPTNO FROM DEPT WHERE DEPTNO 100 AND JOB IN SELECT DISTINCT JOB FROM EMP WHERE DEPTNO 100 GROUP BY DEPTNO, JOB If you did not add the WHERE clause to this query, all rows would be retrieved from the database, regardless of what you selected in Q_Dept and Q_Job. Note: If you added a WHERE clause that did not use the subqueries for example, WHERE EMP.DEPTNO = DEPT.DEPTNO, the query would be executed once for each combination of values in the cross-product. This can lead to excessive execution of the filler query, if the cross-product has a lot of combinations. 4-140 Oracle Reports Users Guide to Building Reports Part I Part I Building Basic Reports The chapters in this Part provide steps to build simple reports. This part contains the following chapters: ■ Chapter 5, Building a Tabular Report A tabular report is the most basic type of report. The output of this report is organized in a multicolumn, multirow format with rows and columns corresponding to those in the database table. ■ Chapter 6, Building a Mailing Label Report A mailing label report is displayed in a format suitable for use as address labels on envelopes. You write custom text and embed database values, or text from files, to create the labels. You can print the labels in one or many columns and at any position. ■ Chapter 7, Building a Form Letter Report A form letter report is displayed in a format suitable for use in printed forms or letters. Similar to the mailing label report, you can write custom text and embed to it, database values or text from files. ■ Chapter 8, Building a MasterMaster Report A master-master report also called a parent-parent report consists of at least two sets of data that are not directly related. This report contains two or more queries with no links that is, no parent-child relationships. ■ Chapter 9, Building a Summary Report A summary report contains a field that summarizes at least one column of the report. This summary can be: total sales, average of a list of commissions, maximum amount found in a series of purchase orders, and so on. Building a Tabular Report 5-1 5 Building a Tabular Report In this chapter, you will learn about tabular reports, the most basic report style. By following the steps in this chapter, you can generate the report output shown in Figure 5–1 . Figure 5–1 Tabular report output Concepts A tabular report is the most basic type of report you can build. The report output is organized in a multicolumn, multirow format, with each column corresponding to a column in the database table. In this example, the column labels Department Id, Department Name , Manager Id, and Location Id are derived from the columns in your SQL SELECT statement, but you can modify column labels as you wish. Data Relationships ■ Generally, the first step is to define the data Oracle Reports should fetch from the database by creating a query that contains a SELECT statement. Although this example report uses only one query, reports can contain any number of queries. ■ For each query you create, Oracle Reports automatically creates one default group. The default query names are Q_1, Q_2, and so on. The default group name is G_ fieldname , where fieldname is the first field of the table specified in the query. For example, if the first field of the table EMPLOYEE is FIRSTNAME, then the default group name is G_FIRSTNAME. ■ For each database column you specify in the querys SELECT statement, Oracle Reports creates a report column and assigns it to the group. By default, the columns appear in the order in which you enter them in your SELECT statement. 5-2 Oracle Reports Users Guide to Building Reports The default column names are generated from the database column names or replaced by any aliases specified in your SELECT statement. ■ If you select two or more columns with the same name, the first column is given the default name, the second column is given the default name with a 1 appended to it for example, Deptno, Deptno1, and so on. Layout ■ Before you can run your report, you must specify the layout that is, the format of the report output. If you do not, Oracle Reports will fetch the data but will not display it; you may receive an error message, depending on whether you choose paper or Web layout. ■ For this example report, you will use the tabular layout style, which is one of eight styles provided by Oracle Reports. The tabular layout displays data in a series of columns running down the page, with the column headings displayed directly above the columns. Example Scenario As you build this example report, you will: ■ Use the Report Wizard to Create a Report with a paper layout that includes one query to select all of the columns displayed in this report. Oracle Reports will create all other necessary objects for example, groups and columns by default. To see a sample tabular report, open the examples folder named tabular, then open the Oracle Reports example named tabular.rdf. For details on how to open it, see Accessing the Example Reports in the Preface.

5.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.

5.2 Use the Report Wizard to Create a Report

When you create a report, you can either use the Report Wizard to assist you or create the report yourself. To build the simple report in this example, you can use the Report Wizard. Using the wizard enables you to define the layout for the report, as well as set the data definition. To create a simple report:

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

2. In the Welcome or New Report dialog box, select Use the Report Wizard, then

click OK. 3. If the Welcome page displays, click Next. 4. On the Report Type page, select Create Paper Layout Only, then click Next. 5. On the Style page, type a Title for your report, select Tabular, then click Next. 6. On the Data Source page, click SQL Query, then click Next. 7. On the Data page, enter the following SELECT statement in the Data Source definition field: Building a Tabular Report 5-3 SELECT ALL DEPARTMENTS.DEPARTMENT_ID, DEPARTMENTS.DEPARTMENT_NAME, DEPARTMENTS.MANAGER_ID, DEPARTMENTS.LOCATION_ID FROM DEPARTMENTS ORDER BY DEPARTMENTS.DEPARTMENT_ID

8. Click Next.

9. On the Fields page, click the double right arrows to move all of the fields to

the Displayed Fields list, then click Next. 10. On the Totals page, click Next. 11. On the Labels page, click Next. 12. On the Template page, select Predefined Template and click Beige, then click Finish to display your report output in the Paper Design view. It should look something like this: Figure 5–2 Paper Design view for the tabular report Tip: This query selects all the department IDs, the department names, the manager IDs, and the location IDs, then sorts the data by the department IDs. Note: You can enter this query in any of the following ways: ■ Copy and paste the code from the provided text file called tabular_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 5.1, Prerequisites for This Example describes the sample schema requirements for this example.