Add a Grid Summary

25-14 Oracle Reports Users Guide to Building Reports Building a Nested Matrix Report 26-1 26 Building a Nested Matrix Report In this chapter, you will learn about nested matrix reports. By following the steps in this chapter, you can generate the report output shown in Figure 26–1 . Figure 26–1 Nested matrix report output Concepts ■ A nested matrix report is a matrix report which contains more than the usual two dimensions across and down of a simple matrix. ■ You can create nested matrix reports with any number of queries. In Section 26.2, Create a Single-Query Matrix , youll create the example nested matrix report using one query. In Section 26.3, Create a Multiple-Query Matrix , youll use multiple queries. In Section 26.4, Create a Multiple-Query Matrix with a Break , you will use not only group hierarchy to nest one dimension within another, but youll also create a true parentchild relationship between the relevant groups by explicitly creating a new group and placing it within the cross product and above the other group. This will restrict the records displayed to only those for which data exists. 26-2 Oracle Reports Users Guide to Building Reports ■ This example report uses a matrix with three dimensions, created by including three columns in the cross product. The cross product is capable of displaying every possible value for three dimensions: two down YEAR and DEPTNO and one across JOB. This method does not include rows that have null values because there is a break group within the cross product group in the data model. As mentioned above, this chapter describes how to create a nested matrix with and without a break group inside of the cross product group so that you can see the difference in the output. ■ The order in which the two down dimensions YEAR and DEPTNO will be displayed is based upon the order in which you position their corresponding groups within the cross product; that is, of YEAR and DEPTNO, youll position YEAR to the left of DEPTNO. This nests DEPTNO inside of YEAR and causes all records for DEPTNO to appear for each value of YEAR, regardless of whether that department has any data for that year. ■ For additional conceptual information, see Section 2.1.7, About nested matrix reports . Example Scenario In this example, you will create a report that cross tabulates salaries by year and department, and by job function. The result is a matrix with job functions listed across the top, years and departments down the side, and sums of salaries in the cells. Thus, you can quickly determine the sum of all of the salaries for clerks in department 20 and compare that value to the one for all clerks in some other department. As you build this example report, you will: ■ Create a Single-Query Matrix . ■ Create a Multiple-Query Matrix . ■ Create a Multiple-Query Matrix with a Break within the cross product group. ■ Format Monetary Values . To see a sample nested matrix report, open the examples folder named nestedmatrix, then open any of the Oracle Reports examples named nested1.rdf, nested2.rdf, or nested3.rdf. For details on how to access them, see Accessing the Example Reports in the Preface. Notes: ■ In a nested matrix report, where you create a matrix query that has a child matrix query, the fields on which you join should be separated into a separate group in your master matrix. Otherwise, on some platforms, only the first group prints. ■ The queries used to select data for those sample matrix reports are not intended as definitive examples of matrix queries. If you are concerned with performance issues, for example, there are alternate methods of querying data that can improve the performance of a matrix report. Refer to the Oracle Reports online Help for details. Building a Nested Matrix Report 26-3

26.1 Prerequisites for This Example

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

26.2 Create a Single-Query Matrix

You can build a matrix report with a single-query in the data model. A single-query data model typically performs better than a multiple-query data model. When you are creating a single-query report, such as this one, you can use the Report Wizard to create the data model and layout simultaneously. To create a data model and layout:

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 Matrix, 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: SELECT TO_CHAR HIREDATE, YY YEAR, DEPTNO, JOB, SUM SAL FROM EMP GROUP BY TO_CHARHIREDATE, YY, DEPTNO, JOB ORDER BY TO_CHARHIREDATE, YY, DEPTNO, JOB 8. On the Rows page: ■ Click YEAR in the Available Fields list and click the right arrow to move this field to the Matrix Row Fields list. YEAR should appear under Level 1. Note: You can enter this query in any of the following ways: ■ Copy and paste the code from the provided text file called nested1_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 26.1, Prerequisites for This Example describes the sample schema requirements for this example. 26-4 Oracle Reports Users Guide to Building Reports Figure 26–2 First matrix row in the Report Wizard ■ Click Level 1 in the Matrix Row Fields list. This step ensures that the next column added will be at Level 2 rather than Level 1. ■ Click DEPTNO in the Available Fields list and click the right arrow to move this field to the Matrix Row Fields list. Notice that it is added under Level 2 rather than Level 1. Figure 26–3 Second matrix row in Report Wizard ■ Click Next. 9. On the Columns page, click JOB and click the right arrow to move this field to the Matrix Column Fields list. JOB should appear under Level 1, then click Next.

10. On the Cell page, click SUM_SAL and click the right arrow to move this field

to the Matrix Cell Fields list, then click Next. 11. On the Totals page, click Next. 12. On the Labels page, change the labels and field widths as follows, then click Next: Building a Nested Matrix Report 26-5

13. On the Template page, make sure Beige is selected under Predefined Template,

then click Finish to display your report output in the Paper Design view. It should look like this: Figure 26–4 Paper Design view for the nested matrix report

26.3 Create a Multiple-Query Matrix

You can build a matrix report with multiple queries in the data model. A multiple-query data model is typically easier to conceptualize and code than a single-query, but the single-query data model typically performs better.

26.3.1 Create a new report manually

In this case, it is easier to create the data model and layout separately. Hence, we will create an empty report first, then add the queries, and then create the layouts. To create a blank report:

1. Choose File New Report.

2. Select Build a new report manually, then click OK.

26.3.2 Create a data model with a cross product and data links

When you create a matrix report with multiple queries, it is typically easier to create all of the queries with the Data Wizard first and then create the cross product group and the necessary links in the Data Model view. Fields Labels Width YEAR no change 4 DEPTNO no change no change JOB no change 10 SUM_SAL none 10 Note: You can set alignment and format monetary values directly in the Paper Design view. Simply click the item, then click the appropriate toolbar button if you run the mouse over these buttons, hint text displays. If the Paper Design view and the Object Navigator are displayed side-by-side, notice that when you select an item in one, the selection is reflected in the other.