Oracle Reports - ConfluentMinds

advertisement
Oracle Reports Builder
1
Objectives
• Generating Reports as per required format and
selection criteria
• Oracle Reports Features and Benefits
• Developing and executing Reports
2
Agenda
•
•
•
•
•
•
•
•
Report Builder Components
Data Model Editor
Layout Editor
Parameter Form
Report Triggers & Program Units
SRW Packages
Report Types
Matrix Report
3
Report Builder Components
Oracle Reports is a tool used to
build reports that dynamically
retrieve, format, and distribute
information which is stored in the
database.
Its Object navigator helps you
navigate among the objects in your
report
The Data Model editor lets you
define the data selection query for
the report.
The Layout editor allows you to
create the report layout
4
Report Builder Components
The Parameter Form editor allows to
customize the appearance of the Runtime
Parameter Form, a window that optionally
appears at runtime and enables you to
enter parameter values that affect report
execution.
The Report Editor's Live Previewer view
enables you to preview and inspect your
report output page by page.
Report triggers execute PL/SQL functions
at specific times during the execution and
formatting of your report.
Program units are packages, functions, or
procedures that you can reference from any
PL/SQL within the current report.
5
Data Model Editor
Data model is composed of :
– Queries
– Groups
– Columns
– Parameters
– Links
• Queries are SELECT statements that fetch data from a
standard database.
• Groups determine the hierarchy of the data appearing in
a report, and are used primarily to create breaks.
6
Data Model Editor
• Columns contain the data values for a report. Default report
columns corresponding to the table columns included in
each query's SELECT list are automatically created by
Oracle Reports, then each column is placed in the group
associated with the query that selected the column.
• If you want to perform summaries and computations on
database column values, you can create new columns.
• Parameters are variables for your report that enable you to
change selection criteria at runtime.
• Data links are used to establish parent-child relationships
between queries and groups via column-matching.
7
Data Model - Query
Create a query with the SQL Query
icon in the Data Model editor.
A default group is created with all the
columns of the SELECT statement.
8
Data Model – Group
 Groups are created to organize the columns in your report.
 Groups can do two things: separate a query's data into sets ,
and filter a query's data
There are two types of groups in Oracle Reports:
Default (created by Oracle Reports)
User-created (created by you)
Break groups are created to produce subtotals
9
Data Model – Column
•
A database column represents a column that is selected by the
query.
• By default, Oracle Reports generate one column for each item
in a query's SELECT list, and assigns each column the data
type and width specified in the database data dictionary. The
default columns are placed in the default group.
• There are two types of columns:
– Default
– User-created
• Summaries
• Formulas
• Place holders
10
Parameters
• Default (system parameters)
• User-created (bind and lexical parameters)
11
User Parameters
• Bind References
– Use a bind reference when you want the parameter to substitute only one value at
runtime. Precede a bind reference with a colon (:), eg:
WHERE 1=1 AND PURC_ORDER.SUPPLIER_NO = :P_SUPPLIERNO
• Lexical References
– Use a lexical reference when you want the parameter to substitute multiple values at
runtime. Precede a lexical reference with an ampersand (&), eg:
Select ename,Job,sal from emp &wh
• The Parameters will be automatically created if not available.
• Set the value of Lexical parameters in Before report trigger as per
business requirement, eg:
If :P_PONO is NULL then
:wh := 'AND PURC_ORDER.SUPPLIER_NO ='''||:P_SUPPLIERNO||'''';
End if;
12
User Parameter
On the parameter
property sheet, you can
specify the list of values
can be derived from a
SELECT statement or
from static values that
you specify.
Enter the parameter's
data type and size. Initial
Value is the default value
for the parameter.
13
Data Model – Data Link
 Data links relate the results of
multiple queries.
A data link (or parent-child
relationship) causes the child
query to be executed once for
each instance of its parent group.
Click on the parent group and
click on the data link icon.
Then click on the master
column of the parent group and
drag to the corresponding
column of the child group.
The link properties can be
viewed as this.
14
Layout Editor
15
Layout
• Layout objects define a report's format; i.e., the positioning and appearance
of data, text, and graphics in the report output.
• It has 3 sections
– Main Section
– Header Section
– Trailer Section
• In every section there is Margin where you can put fields or Boiler plate
texts.
• Various Layout Objects are
– Frames
– Repeating Frames
– Fields
– Boilerplate Text
16
Layout -Frames
A frame contains data and other report
objects.
It prints only as often as the object by
which it is enclosed.
A frame is not record-related
It looks like a rectangle with two diamond
shapes on both vertical sides.
Create frames to group together objects to ensure they maintain
their relative positions during printing
It demarcates sections in your report
17
Layout – Repeating Frames
 A repeating frame is a container for records. It prints once
for each record of the group, with which it is associated.
 It looks like a rectangle with an Arrow which indicates the
direction of printing.
Across: Each instance of the repeating frame subsequent to the first instance
is printed to the right of the previous instance
Across/Down: Each instance of the repeating frame subsequent to the first
instance is printed to the right of the previous instance until the right margin of
the page. Then Report Builder prints the next instance below the left-most
instance on the page.
Down: Each instance of the repeating frame subsequent to the first instance
is printed below the previous instance.
Down/Across: Each instance of the repeating frame subsequent to the first
instance is printed below the previous instance until an entire instance cannot fit
inside the bottom margin of the page. At that time, Report Builder prints the
instance to the right of the topmost instance on the page.
18
Layout –Fields
•Fields refer to columns and
parameters viz:
•&Current Date
•&Logical Page Number
•&Total Logical Pages
•For manually created fields the
source need to be associated
appropriately.
19
Layout –Boilerplate
• Boilerplate is text, lines, or graphics not fetched by a query, yet appearing in
the report output.
• Use boilerplate to customize your report, such as creating heading pages,
adding graphics, etc.
• Boilerplate from Files
• If you have a text or graphic file that you would like to display as boilerplate
in your report, you can:
• Import the contents of the file using the Import dialog box When you import a
file, a boilerplate object is created and the contents of the file are placed in
the boilerplate object. The boilerplate object's contents are static. They
remain the same even if you later change the contents of the file.
• Link to the file Linking to a file means that the contents of the file are pulled
into the boilerplate object each time the report is run. In this way, you can
ensure that your output includes the most recent changes to the file.
20
Layout – Print conditions
•
•
•
•
•
•
•
•
The Print Condition property defines when an object is triggered to print, relative to when its
owner (parent object) prints.
Ownership is determined either by explicit or implicit anchors, or by enclosing an object .
All :Triggers the object to print on all logical pages on which the parent prints (e.G., Column
labels that print on all pages because they are anchored to the page)
All but first :Triggers the object to print on all but the first logical page on which the parent
prints (e.G., Page numbers that begin on page two because they are anchored to the page)
All but last :Triggers the object to print on all but the last logical page on which the parent
prints (e.G., An end-of-page summary that is replaced on the last report page by an end-ofreport summary)
First :Triggers the object to print on only the first logical page on which the parent prints
(e.G., Column labels that only appear once)
Last :Triggers the object to print on only the last logical page on which the parent prints (e.G.,
Summaries or group footers)
Default :Has oracle reports evaluate the object's position to determine which of the above is
most relevant
21
Layout – Concepts (Contd.).
• Page Protect
– The Page Protect property causes all objects within a repeating frame or frame to
remain together on the same logical page, when possible.
– If it is impossible to keep them on the same page, Oracle Reports will let them
span multiple pages.
• Format Triggers
– A format trigger contains PL/SQL executed when the object is formatted
• Page Protect for a repeating frame means that Oracle Reports should protect one
record of the repeating frame.
• For a frame, it means Oracle Reports should protect all enclosed objects, including
all records of any repeating frame enclosed within the frame.
• The Keep with Anchoring Object property causes the parent object to move to the
next page if its child object cannot appear with it on the same page.
• Keep with Anchoring Object uses any existing explicit anchor to determine the
parent. If there is no explicit anchor, an implicit anchor is used.
22
Parameter Form
23
Parameter Form Objects
•Parameter form appears at runtime in
which you can override default
parameter values.
•The Runtime Parameter Form is built
using two report-level objects:
– Fields
– Boilerplate
Boilerplate
Field
24
Parameter Form Field
Field is the actual value of the parameter
that is being captured at run time.
This has the following properties:
•
Name
•
Data type
•
Source
•Source is the parameter from which the parameter
form field gets its value. A list of values is provided and
it contains all parameters in the report.
25
Building a parameter form
• Use Parameter Form Builder
to build the parameter form.
• The Parameter Form Builder
is the work area in which you
select the report's Runtime
Parameters.
• When you run a report, Oracle
Reports uses the Parameter
Form editor as a template for
the Runtime Parameter Form.
• Fields and boilerplate appear
in the Runtime Parameter
Form exactly as they appear
in the Parameter Form editor.
26
Report Triggers & Program Units
27
Report Triggers
• Report triggers are PL/SQL subprograms that fire at specific times
during report execution and formatting.
• Report triggers govern conditional printing.
• Report triggers have PL/SQL packages that enable changing of the
format attributes of an object at run time.
• Report triggers enable changing of properties such as color, style,
format mask, spacing of a field or a boilerplate text.
List of Report Triggers in the order of execution:
•
Before Form
• After Form
•
Before Report
•
Between Pages
• After Report
28
Report Triggers
•
Before Form – Fires before the Runtime Parameter form is displayed. This trigger enables
accessing and changing the values of parameters, PL/SQL global variables and report level
columns.
•
After Form – Fires after the Runtime Parameter form is displayed. This trigger enables
accessing parameters and checking their values. This trigger can also be used to change
parameter vales or, if an error occurs, return to the Runtime Parameter Form. Columns from
the data model are not accessible from this trigger.
•
Before Report – Fires before the report is executed but after queries are parsed and data is
fetched.
•
Between Pages – Fires before each page of the report is formatted, except the very first page.
This trigger can be used for customized page formatting.
•
After Report – Fires after the Previewer is exited, or after report output is sent to a specified
destination, such as a file, a printer. This trigger can be used to clean up any initial processing
that was done, such as deleting tables. This trigger always fires irrespective of whether or not
the report completes successfully.
29
Create a PL/SQL
•
•
•
Report program units are
packages, functions, or
procedures that you can
reference from any PL/SQL
within the current report.
In the Object Navigator,
select the Program Units
node, then select Navigator->Create (or the Create tool).
In the Program Unit editor,
click in the Source Text field
and type or modify the text
of the subprogram.
30
Open a PL/SQL
In the Object Navigator:
• Double-click on the P icon in the subprogram under
the Program Units node.
• Or, if you know what object references the PL/SQL,
double-click on the PL/SQL icon in the node that
represents the object.
• In the Program Unit editor, modify the text of the
subprogram as desired.
31
SRW Packages
32
SRW Packages
•Oracle Reports is shipped with a collection of PL/SQL constructs called SRW (SQL
Report Writer) package which contain many functions, procedures and exceptions that
can be referenced in your libraries or reports viz.
•SRW.MESSAGE(msg_number NUMBER, msg_text CHAR);
• Displays a specified message and message number.
• SRW.DO_SQL(sql_statement CHAR);
• Executes specified SQL statement.
• SRW.DO_SQL_FAILURE;
• Stops report execution upon SRW.DO_SQL failure.
•SRW.PROGRAM_ABORT;
• Stops execution of report when raised.
• SRW.RUN_REPORT(command_line CHAR);
• Executes specified R25RUN command
• SRW.RUN_REPORT_FAILURE;
• Stops report execution when failure of SRW.RUN_REPORT occurs.
33
Report Types
34
Report Types
• Tabular
• Mailing Label
• Form Letter
• Master/Master Report
• Master/Detail Report
• Group Left
• Group Above
35
Tabular Report
A tabular report is the most basic type of report you can
build. The report output is organized in a multi-column,
multi-row format, with each column corresponding to a
column in the database table.
36
Mailing Label Report
A mailing label report consists of data displayed in a format
suitable for use as address labels on envelopes. The labels
can be printed in one or many columns, and can begin at
any position.
37
Form Letter Report
•Form letter reports contain database values embedded in boilerplate
text.
•Boilerplate text can be defined as any text that appears each time the
report is run
38
Master/Master Report
A master/master report displays at least two sets of data which are not
directly related--that is, the records constituting the data are fetched using
at least two separate queries
39
Break Report (Group Left)
Break reports divide the rows of a table into "sets," based on a
common value in one of the columns.
40
• Create a break report when you want to prevent a column
from repeatedly displaying the same value while other
column values in the rows change. A break report resembles
a master/detail (or parent/child) report in that one master
record prints, followed by all the detail records with which
the master has something in common.
• Reset Level
• The reset level, also known as the reset group, determines
when to reset the value of the summary column to zero--in
other words, how much of the source column to summarize.
41
Break Report (Group Above)
42
Master/Detail Report
•A simple master/detail report contains two groups of data: the
master group and the detail group.
• Master/detail reports are similar to break reports in the way
they fetch data; for every master or break group, related detail
records are fetched.
43
Matrix Report
• A matrix (cross tab) report contains one row of
labels, one column of labels, and information
in a grid format that is related to the row and
column labels.
• A distinguishing feature of matrix reports is
that the number of columns is not known until
the data is fetched from the database.
44
Matrix Report
A matrix report is a cross-tabulation of four sets of data:
• One set of data is displayed across the page.
• One set of data is displayed down the page.
• One set of data is the cross-product, which determines all
possible locations where the across and down data relate
and places a cell in those locations.
• One set of data is displayed as the "filler" of the cells.
45
Matrix Report
Queries
• Although matrix report always require at least four groups, they can be
built with any number of queries. If you build a matrix report with only one
query (usually the most efficient structure), you must create at least three
groups manually in addition to the one created by default.
46
Matrix Report
Group Structure
• Two dimension groups.
Dimension groups are created for row and columns of the Matrix report.
• One cross product groups.
The cross product group represents all possible combinations of the values of
the dimension groups. In the layout, the cross product group is represented by
the intersection of the repeating frames for the across and down dimension
groups
• One cell, or "filler" group.
The cell group contains the actual information that is represented by the cells of
the cross product.
47
Matrix Layout
A Matrix Report Layout should contain:
• At least two repeating frames, one with a print direction of
down and one with a print direction of across
• A matrix object created for the cross product group, inside of
which reside the cells of the matrix
• Boilerplate for each column and row of values, as well as for
summaries .
48
Thank You
49
Download