Skip Headers
Oracle® Fusion Middleware Oracle Reports User's Guide to Building Reports
11g Release 1 (11.1.1)

Part Number B32122-03
Go to Documentation Home
Home
Go to Book List
Book List
Go to Table of Contents
Contents
Go to Index
Index
Go to Master Index
Master Index
Go to Feedback page
Contact Us

Go to previous page
Previous
Go to next page
Next
PDF · Mobi · ePub

4.8 Work with the Data Model

This section provides procedures for the following tasks that you may perform as you work with the data model of your report:

4.8.1 Creating a query

To create a query, you can use any of the following tools:

  • Report Wizard (single-query reports only)

  • Data Wizard

  • SQL Query tool (to create a query that selects data from an Oracle relational database)

  • XML Query tool (to access an XML data file, if you have the DTD file)

  • JDBC Query tool (to access any JDBC-enabled data source)

  • Text Query tool (to create a query that selects data from a text pluggable data source)

  • REF CURSOR Query tool (to use REF CURSORs)

See also

Section 1.7.1, "About queries"

Section 1.7.3, "About database columns"

4.8.1.1 Creating a query: Report Wizard

To create a query using the Report Wizard:

  • On the Data page of the Report Wizard, enter the query statements for the type of data source previously selected. For example, if you selected the SQL Query data source, you can enter your SQL query in any of the following ways:

    • Type the SELECT statement in the Data Source definition field.

    • Click Query Builder for a graphical method of creating a query without a knowledge of SQL.

    • Click Import Query to use a query that has been written by someone else or to use the text editor of your choice.

4.8.1.2 Creating a query: Data Wizard

To create a query using the Data Wizard:

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

  2. Follow the wizard to create the first query for the data model.

  3. Repeat Steps 1 and 2 for each query you want to create.

  4. Modify the resulting data model in the Data Model view.

  5. To re-enter the Data Wizard, do either of the following:

    • Right-click, and choose Data Wizard.

    • Click the query, then choose Edit > Settings.

      Note:

      The Data Wizard does not support creating links between queries. To define parent/child query relationships, you can create a data link manually.

4.8.1.3 Creating a query: SQL Query tool

To create a SQL query:

  1. In the Data Model view, click the SQL Query tool in the tool palette then click in an open area of the Data Model view to display the SQL Query Statement dialog box.

  2. In the SQL Query Statement field, define a SELECT statement for the query in any of the following ways:

    • To use Query Builder for an easy graphical method of creating a query without a knowledge of SQL, click Query Builder.

    • To import a query from a file, click Import Query.

    • To enter the SELECT statement yourself, type it in the SQL Query Statement field.

      Tip:

      Select the columns in the order you want them to appear in the report output.

  3. Click OK.

  4. Refine the query using either of the following methods:

    • Right-click the query object, then choose Property Inspector to set desired properties.

    • Right-click the query object, then choose Data Wizard to specify which fields to display, group fields, and any totals.

  5. Repeat Steps 1 through 5 for each query you want to create.

    Note:

    If you define multiple queries in the Data Model view of your report, the Data page does not appear when you invoke the Report Wizard to default the layout.

4.8.1.4 Creating a query: XML Query tool

To create an XML query:

  1. In the Data Model view, single-click the XML Query tool in the tool palette.

  2. Click in the main area (canvas region) of the window.

  3. In the Define XML Query dialog box, define the XML query based on the fields defined in the data definition file (DTD) selected. The query is run against the data in the XML data file. If an XSL file is specified, it translates the XML data file before running the query.

  4. Click OK.

4.8.1.5 Creating a query: JDBC Query tool

To create a JDBC query:

  1. In the Data Model view, single-click the JDBC Query tool in the tool palette.

  2. Click in the main area (canvas region) of the window.  

  3. In the JDBC Query dialog box, define the JDBC query or procedure and the connection parameters for the data source. Click Help for assistance.

  4. Click OK.

4.8.1.6 Creating a query: Text Query tool

To create a Text query:

  1. In the Data Model view, single-click the Text Query tool in the tool palette.

  2. Click in the main area (canvas region) of the window.

  3. In the Define Text Query dialog box, specify the data definition and data source for the text query. Click Help for assistance.

  4. Click OK.

4.8.1.7 Creating a query: REF CURSOR Query tool

To create a REF CURSOR query:

  1. Create a package that defines a REF CURSOR type in one of the following ways:

  2. If the package created in Step 1 is an external PL/SQL library, you must attach it to the report before referencing it.

  3. In the Data Model view, single-click the REF CURSOR Query tool in the tool palette.

  4. Click in the main area (canvas region) of the window.

  5. In the PL/SQL Editor, type the PL/SQL for a function that opens a cursor and returns a cursor variable of the REF CURSOR type you defined in the package. For example:

    empCur rcPackage.empCurType;
    
    BEGIN
      OPEN empCur FOR SELECT * FROM emp;
      RETURN empCur;
    END; 
    
    /* Note, rcPackage is a local program unit defined as: */
    PACKAGE rcPackage IS
      TYPE empCurType IS REF CURSOR RETURN emp%ROWTYPE;
    END; 
    

    Note:

    Oracle Reports supports both static and dynamic REF CURSORs. For more information, see Section 2.6.10, "About REF CURSOR queries".

  6. Refine the query as desired:

    • Click the REF CURSOR query object, then choose Tools > Property Inspector to modify properties.

    • Click the query object, then choose Tools > Data Wizard to specify which fields to display, group fields, and any totals.

  7. Repeat Steps 1 through 6 for each REF CURSOR query you want to create.

See also

Section 2.6.10, "About REF CURSOR queries"

4.8.2 Modifying a query

To modify a SQL query statement or the columns displayed in your report:

  1. In the Data Model view, click the query object, then right-click and choose Data Wizard.

  2. To change the SELECT statement, click the Data tab.

  3. To change the break groups, click the Groups tab.

  4. To add or change summary columns for totals, click the Totals tab.

  5. To change which selected database columns are displayed in your report, choose Tools > Report Wizard, then click the Fields tab.

To modify the properties of a query:

  1. In the Data Model view, click the query object, then right-click and choose Property Inspector.

  2. In the Property Inspector, modify the properties as desired.

4.8.3 Using Query Builder

You can use Query Builder to define almost any query that you would build using a SQL SELECT statement. Query Builder automatically generates the appropriate SELECT FROM [table.column] clause based on columns displayed in the Query Builder workspace.

See the How To section of the Oracle Reports online Help for topics about using Query Builder.

See also

Section 1.7.5, "About Query Builder"

4.8.4 Selecting HTML tags from the database

Note:

This procedure applies to paper-based reports.

To select HTML tags from the database:

  1. Create a query, with a SELECT statement that selects a column containing HTML tags or the names of files that contain HTML tags.

  2. In the Data Model view, double-click the HTML tags column to display the Property Inspector.

  3. If the column contains the names of files that contain the HTML tags, rather than the HTML tags themselves:

    • Under the Column node, set the Read from File property to Yes.

    • Set the File Format property to Text.

  4. In the Paper Layout view, create a field object that references the column.

  5. Double-click the field object to display the Property Inspector.

  6. In the Property Inspector, under the Web Settings node, set the Contains HTML Tags property to Yes.

Usage notes

When the text object's Contains HTML Tags property is set to Yes, HTML tags and attributes are formatted in your report output as follows:

  • If the report is generated to HTML or HTMLCSS output, all HTML tags and attributes are interpreted and formatted in the output.

  • If the report is generated to other bitmap output formats (for example, PDF, RTF, PostScript), a fixed set of HTML tags and attributes are interpreted and formatted in the output, as described in Section 2.8.9, "About HTML formatting". Any HTML not in the supported set of tags and attributes are not interpreted, and appear as is in the report output.

4.8.5 Selecting an image from the database

Note:

These steps, and the steps in Section 4.9.8.1.2, "Linking an image object to a file" (for paper-based reports only), allow you to include images in a wide variety of formats supported by Oracle Reports, including JPEG (all types, such as Progressive JPEG and Exif JPEG), PNG, BMP, TIFF, GIF, and CGM. For paper-based reports, you can also use Insert > Image to import an image from a file into the report layout for images in the following formats: TIFF, JFIF, BMP, TGA, PCX, PICT, GIF, CALS, RAS, OIF, PCD (see Section 4.9.8.1.1, "Importing an image").

To select an image from the database:

  1. Create a query that selects a column containing images or the filenames of image objects.

  2. In the Data Model view, double-click the image column to display the Property Inspector.

  3. If the column contains the filenames of image objects, rather than the images themselves:

    • Under the Column node, set the Read from File property to Yes.

  4. In both cases (a column containing images or a column containing the filenames of image objects): under the Column node, set the File Format property to Image.

  5. If you are developing a JSP-based Web report, you will also need to add the containsHtml attribute to the <rw:field> JSP tag for the column, as follows:

    • Display the Web Source view for the report.

    • Search for the rw:field tag for the column (<rw:field ... src="column_name" ...>)

    • Add the containsHtml=yes attribute to specify that the field's value contains an image.

      For example:

      <rw:field id="F_MYIMAGE" src="MYIMAGE" nullValue="&nbsp;" containsHtml="yes">
      
  6. To preview your report output with Web layout in a Web browser, choose Program > Run Web Layout to run the Web Source. If you have made changes to the Web Source view (for JSP-based Web reports), this enables you to immediately see the effect of your changes on the output.

See also

Section 2.4.3, "About images"

Section 1.7.3, "About database columns"

4.8.6 Selecting an image URL from the database

Notes:

This procedure is for HTML output only.

These steps, and the steps in Section 4.9.8.1.3, "Linking an image object to a URL" (for paper-based reports only), allow you to include images in a wide variety of formats supported by Oracle Reports, including JPEG (all types, such as Progressive JPEG and Exif JPEG), PNG, BMP, TIFF, GIF, and CGM. For paper-based reports, you can also use Insert > Image to import an image from a file into the report layout for images in the following formats: TIFF, JFIF, BMP, TGA, PCX, PICT, GIF, CALS, RAS, OIF, PCD (see Section 4.9.8.1.1, "Importing an image").

To select a URL from the database that point to an image to include in an HTML report:

  1. Create a query, with a SELECT statement that selects a column containing URLs.

  2. In the Data Model view, double-click the column containing the URLs to display the Property Inspector.

  3. Under the Column node:

    • Set the Read from File property to Yes.

    • Set the File Format property to Image URL.

  4. If you are developing a JSP-based Web report, you will also need to add the containsHtml attribute to the <rw:field> JSP tag for the column, as follows:

    • Display the Web Source view for the report.

    • Search for the rw:field tag for the column (<rw:field ... src="column_name" ...>)

    • Add the containsHtml=yes attribute to specify that the field's value contains an image.

      For example:

      <rw:field id="F_MYIMAGE" src="MYIMAGE" nullValue="&nbsp;" containsHtml="yes">
      
  5. To preview your report output with Web layout in a Web browser, choose Program > Run Web Layout to run the Web Source. If you have made changes to the Web Source view (for JSP-based Web reports), this enables you to immediately see the effect of your changes on the output.

See also

Section 2.4.3, "About images"

Section 2.8.8, "About HTML and HTMLCSS output"

4.8.7 Creating a break group

You can define break groups in the Report Wizard or create them manually.

To create a break group manually:

  1. In the Data Model view, drag the group that contains the column at which you want to break your report down from the query object about 2 inches (5 centimeters).

  2. Select the column that you want to use to divide your report (for example, if you want to group a list of employee data by department number, select the department number column) and drag it out of and above the group to create a new group. This is the break column.

  3. Double-click the new group object to display its Property Inspector, where you can set properties for the break group.

See also

Section 1.7.2, "About groups"

Section 1.3.2, "About group above reports"

Section 1.3.3, "About group left reports"

4.8.8 Creating a matrix (cross-product) group

You can define matrix groups in the Data Wizard or create them manually.To create a matrix (cross-product) group using the Data Wizard:

  1. In the Data Model view, right-click and choose Data Wizard.

  2. On the Query page, select the Matrix query check box.

  3. Follow the wizard to select the columns for the matrix group(s), rows, columns, and cells.

    To create a matrix (cross-product) group manually:

  4. In the Data Model view, drag the title bar of the group object down.

  5. Drag the "row" column and "column" column out of the group object into the space to create two new groups.

  6. Single-click the Cross Product tool in the tool palette.

  7. Drag a box around the groups you want to include in the matrix (cross-product) group.

  8. If the cell group is a separate query from the matrix (cross-product) groups, create the appropriate links between the columns in the matrix groups and the cell group.

See also

Section 2.3.7, "About matrix objects"

Section 1.3.7, "About matrix reports"

Section 2.1.7, "About nested matrix reports"

Section 2.1.8, "About matrix with group reports"

Section 1.7.2, "About groups"

Section 4.9.1.3, "Creating a matrix object"

Section 4.5.3, "Creating a nested matrix report"

Section 1.3.2, "About group above reports"

Section 1.3.3, "About group left reports"

4.8.9 Creating a data link

To create a data link:

  1. In the Data Model view, single-click the Data Link tool in the tool palette. A link is always drawn from the parent group to the child query.

  2. Create the link:

    Create a Group to Group Link: To create a link between one query's group and another query's group, which is useful when you want the child query to know about the parent's data, click the parent group (avoiding the columns in the group) and drag a link to the child group.

    Create a Column to Column Link: To create a link between columns, click a column of the parent query and drag a link to a column of the child query.

  3. Double-click the new link object to display the Property Inspector, and set the desired properties.

See also

Section 1.7.4, "About data links"

Section 2.3.5, "About non-linkable queries"

4.8.10 Creating or editing a formula column

To create or edit a formula column:

  1. In the Data Model view, single-click the Formula Column in the tool palette, then:

    • To create a column within a group, click in the group at the position you want the column placed in the hierarchy.

    • To create a report-level column, click in an open area of the canvas region.

  2. Double-click the formula column object to display the Property Inspector.

  3. Under the Placeholder/Formula node, double click the PL/SQL Formula property field.

  4. In the PL/SQL Editor, define the PL/SQL for the formula for example SAL * 0.07.

Example: Referencing a PL/SQL function in formulas

Suppose that you have a report with the following groups and columns:

Groups  Columns         Summary
---------------------------------------
RGN     REGION
        RGNSUMSAL       SUM(DEPTSUMSAL)
        COSTOFLIVING
                
DEPT    DNAME
        DEPTNO
        DEPTSUMSAL      SUM(EMP.SAL)
 
JOB     JOB
        HEADCOUNT       COUNT(EMP.EMPNO)
 
EMP     ENAME
        EMPNO
        SAL
        COMM

Given these groups and columns, you might create multiple formulas that apply the cost of living factor (COSTOFLIVING) to salaries. To avoid duplication of effort, you could create the following PL/SQL function and reference it from the formulas:

function CompSal(salary number) return number is
begin
  return (salary*CostofLiving);
end;

Following are some examples of how you might reference the PL/SQL function in formulas:

CompSal(:RGNSUMSAL)

or

CompSal(:SAL) + COMM

See also

Section 2.3.2, "About formula columns"

4.8.11 Creating a summary column

To create a summary column (for totals or subtotals) using the Data Wizard:

  1. In the Data Model view, click the query that contains the column you want to total.

  2. Choose Tools > Data Wizard.

  3. On the Totals page, follow the wizard to add the desired summary to your report.

    Note:

    For group reports, the Report Wizard and Data Wizard create n summary fields in the data model for each summary column you define: one at each group level above the column being summarized, and one at the report level. For example, if a report is grouped by division, and further grouped by department, then a summary column defined for a salary total would create fields for the sum of salaries for each division and each department group (group-level summaries), and the sum of all salaries (report-level summary).

To create a summary column (for totals or subtotals) using the tool palette:

  1. In the Data Model view, single-click the Summary Column tool in the tool palette, then:

    • To create a column within a group, click in the group at the position you want the column placed in the hierarchy.

    • To create a report-level column, click in an open area of the canvas region.

  2. Double-click the new summary column object to display the Property Inspector.

  3. Under the Summary node:

    • Set the Function property by choosing the type of summary you want from the list.

    • Set the Source property to the column you want to summarize.

    • Set the Reset At property to the group at which the summary column value resets.

Usage notes

For JSP-based Web reports with a Group Above or Matrix style, if any summary column values are not correctly left-aligned when you click the Run Web Layout button in the toolbar (or choose Program > Run Web Layout), you can implement the following workaround to align the values:

  • In the Web Source view, locate the section where the summary column is defined, and delete the following line to remove the extra space:

    <th class="summary_column_name"> </th>
    

See also

Section 2.3.1, "About summary columns"

Chapter 9, "Building a Summary Report"

Chapter 13, "Building a Group Left Summary Report"

4.8.12 Creating or editing a placeholder column

To create or edit a placeholder column:

  1. In the Data Model view, single-click the Placeholder Column tool in the tool palette.

    • To create a column within a group, click in the group at the position you want the column placed in the hierarchy.

    • To create a report-level column, click in an open area of the canvas region.

  2. Double-click the placeholder column object.

  3. In the Property Inspector, set the desired properties for the placeholder column.

  4. Set the value of a placeholder column in:

    • the Before Report trigger, if the placeholder is a report-level column

    • a report-level formula column, if the placeholder is a report-level column

    • a formula in the placeholder's group or a group below it (the value is set once for each record of the group)

See also

Section 2.3.2, "About formula columns"