Skip Headers

Oracle Reports Building Reports
10g (9.0.4)

Part Number B10602-01
Go To Documentation Library
Home
Go To Table Of Contents
Contents
Go To Index
Index

Go to previous page Go to next page

11
Building a Two-Query Group Report

Figure 11-1 Group above report output, two queries

Text description of grp_abv2_fin.gif follows.

Text description of the illustration grp_abv2_fin.gif

As you can see above, a two-query group report appears much the same as a single-query group report. Performance is the key issue when contrasting single-query and multiple-query group reports. In most cases, single-query reports will run faster than multiple-query reports. The multiple-query reports are, however, sometimes easier to understand conceptually and easier to maintain. For example, if you are in a situation where only a few users run the report and the report returns a relatively small number of records, you might want to use multiple queries to simplify maintenance and make the data model easier to understand. If you have many users and the report is quite large, then you should try to use a single-query report.

Concepts

Example Scenario

Suppose that you want to create a group above report that lists employees with their jobs and salaries by department.

To see a sample group above report with two queries, open the examples folder named masterdetail, then open the Oracle Reports example named grp_abv2.rdf. For details on how to access it, see "Accessing the example reports" in the Preface.

Table 11-1 Features demonstrated in this example
Feature Location

Create a new, empty report

Section 11.2, "Create a new report manually"

Create two queries with a data link between them

Section 11.3, "Create a data model with a data link"

Layout the data

Section 11.4, "Use the Report Wizard to layout the data"

Format monetary values

Section 11.5, "Format a field"

11.1 Prerequisites for this example

To build the example in this chapter, you must have access to the Summit Sporting Goods schema, which we've provided on the Oracle Technology Network (http://otn.oracle.com/products/reports/). To download the SQL scripts that install the schema, go to the Documentation page on OTN and follow the instructions provided on the Web page.

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

11.3 Create a data model with a data link

When you create a report with multiple queries, it is typically easier to create all of the queries with the Data Wizard first and then create the layouts with the Report Wizard.

To create the queries:

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

  2. If the Welcome page displays, click Next.

  3. On the Query page, type Q_Salesrep for the Query name and click Next.

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

  5. On the Data page, in the Data Source definition field, enter the following SELECT statement:

    SELECT ENAME, EMPNO
    FROM EMP
    WHERE JOB = 'SALESMAN'
    


    Note:

    You can enter this query in any of the following ways:

    • Copy and paste the code from the provided text file called grp_abv2_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.


  • Click Next.


    Note:

    If you are not already connected to a database, you will be prompted to connect to the database when you click Next. Ensure that you connect to a database that has the appropriate schema for this example. Section 11.1, "Prerequisites for this example" describes the sample schema requirements for this example.


    1. On the Groups page, click Next.

    2. Click Finish to display the data model for your report in the Data Model view.

    3. Repeat the steps above for a second query, but this time name your query

      Q_Product and use the following SELECT statement:

      SELECT REPID, PRODNAME, AMOUNT, CUSTNAME
      FROM SALES
      ORDER BY REPID, CUSTNAME
      

      Figure 11-2 Two-query data model without a link

      Text description of grp_abv2_dm_nolink.gif follows.

      Text description of the illustration grp_abv2_dm_nolink.gif

      To add the data link

      1. In the Data Model view, click the Data Link tool in the tool palette.

      2. Click and drag from the EMPNO column in the G_ENAME group to the REPID column in the G_REPID group. Notice that a line is drawn from the bottom of the G_ENAME group to the Q_Product query. Labels for EMPNO and REPID are created at each end of the line to indicate they are the columns linking G_ENAME to Q_Product.

      Figure 11-3 Two-query data model with a data link

      Text description of grp_abv2_dm_link.gif follows.

      Text description of the illustration grp_abv2_dm_link.gif

      1. Double-click the new data link line to display the Property Inspector and examine the property settings:

        • G_ENAME is identified as the parent, while Q_Product is listed as the child. In terms of the data, the sales rep's name and employee number make up the master record and should print once for the associated product information retrieved by the Q_Product query.

        • Notice that WHERE already appears in the SQL Clause property. WHERE is the default clause used in master/detail relationships. You can replace WHERE with other SQL clauses such as HAVING and START WITH, but for this report the default is correct.

        • The other point to notice is that an equal sign (=) appears in the Condition property. An equality (i.e., table1.columnname = table2.columnname) is the default condition for master/detail relationships defined via a data link. You can replace the equal sign with any other supported conditional operator (to see what's supported, click on the field), but for this report the default is the proper condition.

        Linking the group G_ENAME and the query Q_Product via the EMPNO and REPID columns is analogous to writing both queries as the single-query shown below:

        SELECT ENAME, EMPNO, REPID,
        PRODNAME, AMOUNT, CUSTNAME
        FROM EMP, SALES
        WHERE JOB = 'SALESMAN'
        AND EMPNO = REPID (+)
        ORDER BY REPID, CUSTNAME
        

        11.4 Use the Report Wizard to layout the data

        Once your data model is complete, you need to create a layout for the data objects to display in the report output. The Report Wizard enables you to create layouts for your data model.

        Tip:

        When you have multiple queries in your data model, make sure that you check the names of the groups associated with each query prior to entering the Report Wizard. The Report Wizard requires you to choose data for the layout by group name.

        To create the layout:

        1. In the Data Model view, right-click on the canvas, then choose Report Wizard.

        2. In the Report Wizard, on the Report Type page, select Create Paper Layout only.

        3. On the Style page, select Group Above.

        4. On the Groups page, ensure that both groups from your data model appear in the Displayed Groups list.

        5. On the Fields page:

          • Click the double right arrows (>>) to move all of the fields to the Displayed Fields list.

          • Click REPID in the Displayed Fields list and click the left arrow (<) to move it back to the Available Fields list. Since REPID and EMPNO represent the same value, you only need to display one of them. EMPNO is part of the master group, which is the level where we want to see its values in the report. REPID is part of the detail group. Hence, you remove REPID from the Displayed Fields list to prevent it from appearing in the output.

        Figure 11-4 Fields page of the Report Wizard

        Text description of grp_abv2_coldisp.gif follows.

        Text description of the illustration grp_abv2_coldisp.gif

        1. On the Labels page, change the labels and field widths as follows:

          Table 11-2 Field description of Lables page
          Fields Labels Width

          PRODNAME

          Product

          22

          AMOUNT

          (no change)

          10

          CUSTNAME

          Customer

          15

          ENAME

          Name

          (no change)

          EMPNO

          Emp. No.

          (no change)

        1. 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 11-5 Paper Design view for the two-query group report

        Text description of grp_abv2_out1.gif follows.

        Text description of the illustration grp_abv2_out1.gif

        11.5 Format a field

        In the Paper Design view, notice the Amount field. The values are neither aligned nor displayed as monetary amounts. You can quickly rectify this in the Paper Design view.

        To assign a format mask to monetary values:

        1. In the Paper Design view, select the first number value underneath the Amount label. Notice that all of the values are immediately selected, indicating that you can change their properties simultaneously.

        2. Click the Currency button in the toolbar. A currency symbol immediately appears next to all of the values.

        3. Click the Add Decimal Place tool twice. Two decimal places are added to the right of the decimal point.

        4. Resize the field by clicking and dragging the rightmost handle of the field approximately a 0.5 inches to the left.

        5. Click the Align Right tool. All of the values are immediately right aligned.

        6. Select the Amount label.

        7. Click the Align Right tool.

        8. Save your report.

        The final report output should look something like this:

        Figure 11-6 Group above report output with monetary values formatted

        Text description of grp_abv2_fin.gif follows.

        Text description of the illustration grp_abv2_fin.gif

        11.6 Summary

        Congratulations! You have successfully created the two-query, group report. You now know how to:

        • create queries with a data link between them in the Data Model view.

        • layout the data with the Report Wizard.

        • format a field in the Paper Design view.

        For more information on any of the wizards, views, or properties used in this example, refer to the Reports Builder Online help, which you can access in two ways:


  • Go to previous page Go to next page
    Oracle
    Copyright © 2002, 2003 Oracle Corporation.

    All Rights Reserved.
    Go To Documentation Library
    Home
    Go To Table Of Contents
    Contents
    Go To Index
    Index