Oracle Reports Building Reports Release 6i A73172-01 |
|
The report described in this chapter is designed to help you learn more about Report Builder features for using ref cursors. To build this report, you will use the Data Model view to create a multi-query data model, and then use the Report Wizard to create the report layout. You will make fairly extensive manual refinements in the Data Model view. In this example, you will create a detailed report showing information about available shipping containers at various ports.
A ref cursor query uses PL/SQL to fetch data. Each ref cursor query is associated with a PL/SQL function that returns a strongly typed ref cursor. The PL/SQL function must ensure that the ref cursor is opened and associated with a SELECT statement that has a SELECT list that matches the ref cursor type. You base a query on a ref cursor when you want to:
Furthermore, if you use a stored program unit to implement ref cursors, you receive the added benefits that go along with storing program units in the Oracle database.
The following figure shows that you create a report with the SELECT statement in the ref cursor query of the report. It also shows that you can store the SELECT statement in a package in the database. Then, from the report, you can call the package from the database allowing you to reuse the package in many reports.
Table 6-1, "Features demonstrated in this Ref Cursor Query sample report", describes the steps you will take to create this report.
The ref.rdf
file contains the report you will create after finishing the tasks in this chapter. You may want to refer to this file while you are working. In addition, the port_container.pll
is the library file that is associated with ref.rdf
. These files are located in your ORACLE_HOME\TOOLS\DOC60\US\RBBR60
directory.
To get started, open Report Builder. If the Welcome dialog box appears, click Build a new report manually and click OK. If not, choose File->New->Report. Click Build a new report manually, and click OK.
At some point before you generate the report, you will need to log into the database. Choose File->Connect to connect to the database. Enter the appropriate log on information. See Section 1.3, "Obtaining database access before you start" for details.
To create a ref cursor query, you first create a package spec that defines the ref cursor. Then you create a query that uses the ref cursor. The steps in this section will help you create package specs that define ref cursors.
|
concl_cv
as the name of the program unit.
PACKAGE concl_cv IS
type conclass_rec is RECORD
(ccap number,
classid number,
gwl number,
twl number,
htf number,
hti number,
notes varchar(50),
teu number);
type conclass_refcur is REF CURSOR return conclass_rec;
END;
This package spec does two things:
PACKAGE cont_cv IS
type container_rec is RECORD
(title varchar(40),
dockloc varchar(10),
portid number,
repno varchar(10),
status number,
key varchar(10),
key2 varchar(10),
classid2 number);
type container_refcur is REF CURSOR return container_rec;
END;
ref_61.rdf
.
Tip: It is good practice when you are designing your report to save it frequently under a different file name. If you generate an error or if you don't like some of the changes you made, you easily can go back to the previously saved file and make revisions from that point.
After creating package specs that define the ref cursors, you are ready to define the queries, as described in this section.
function
q_portdesc
RefCurDS return
port_cv.portdesc_refcur
is
temp_portdesc port_cv.portdesc_refcur;
begin
open temp_portdesc for select portid, locname from portdesc;
return temp_portdesc;
end;
q_portdesc
.
Tip: It is usually a good idea to give objects meaningful names, particularly when building a report with many objects. Later when building the layout, it is helpful to have queries and groups with meaningful names.
function
q_container
RefCurDS return
cont_cv.container_refcur is
temp_container cont_cv.container_refcur;
begin
open temp_container for select cl.title, c.DOCKLOC,
c.PORTID, c.REPNO,
c.STATUS, c.key,
cl.key key2, c.classid classid2
from CONTAINERS c, conlabel cl
where cl.key=c.key
order by c.REPNO;
return temp_container;
end;
function q_conclassRefCurDS return concl_cv.conclass_refcur is temp_concl concl_cv.conclass_refcur; begin open temp_concl for select CCAP, CLASSID, GWL, TWL, HTF, HTI, NOTES, TEU from CONCLASS; return temp_concl; end;
In this section you will rename some of the objects in the data model so that they have more meaningful names. You will also create a break group.
|
G_conlabel
.
G_portdesc
.
G_conclass
.
Currently, the queries that you have created are unrelated. To create relationships between them, you need to create group-to-group data links. The steps in this section will help you create the links.
|
After where cl.key=c.key
, add the following code:
and :portid=c.PORTID
Note that :portid
is a bind variable referring to the PORTID column in G_portdesc.
FROM CONCLASS
and the semicolon (;), and press ENTER or RETURN to create a new line.
where :classid2=conclass.classid
Tip: Be sure that the semicolon (;) now follows the WHERE clause.
Note that :classid2
is a bind variable referring to the CLASSID2 column in G_container.
ref_64.rdf
.
Now that your queries are complete and linked, the steps in this section will help you to create columns to summarize the data.
|
CS_classcount
.
Property | Setting |
---|---|
Function |
Count |
Source |
KEY |
Reset At |
G_container |
You have now created a summary that counts up the number of containers. You will not use the summary in this report's layout, but you will use it as the source for other, more interesting summaries later.
Create in Group | Name | Function | Source | Reset At |
---|---|---|---|---|
G_conlabel |
CS_conlabel_classcount |
Sum |
CS_classcount |
G_conlabel |
G_portdesc |
CS_port_count |
Sum |
CS_conlabel_classcount |
G_portdesc |
You may not understand these summaries now. Their purpose will become clearer when you create the report layout and preview the live data.
Your data model should look similar to the following figure:
ref_65.rdf
.
Now that you have a working data model, the steps in this section will help you to create a layout.
Pacific Intermodal Leasing
as the Title.
ref_66.rdf
.
In your current report configuration, the SELECT statements used by the ref cursor queries reside within the report itself. In many cases, it is advantageous to have SELECT statements reside in the packages that define the ref cursor types. Then, you can simply reference the packages, rather than typing the same SELECT statement directly into every report that uses it. If you need to change the SELECT statement (for example, to modify or add clauses), you simply update it once in the package, rather than in every report that uses it.
The steps in this section will help you to move the SELECT statements to the packages that define the ref cursor types.
cont_cv
as the name of the program unit.
PACKAGE BODY cont_cv IS function query_container (p_portid number) return container_refcur is tempcv_container cont_cv.container_refcur; begin open tempcv_container for select cl.title, c.DOCKLOC, c.PORTID, c.REPNO, c.STATUS, c.key, cl.key key2, c.classid classid2 from CONTAINERS c, conlabel cl where cl.key=c.key and p_portid=c.PORTID order by c.REPNO; return tempcv_container; end; END;
In the Object Navigator, double-click the CONT_CV(Package Spec) object.
function query_container (p_portid number) return container_refcur;
function q_containerRefCurDS return cont_cv.container_refcur is temp_container cont_cv.container_refcur; begin temp_container:=cont_cv.query_container (:portid); return temp_container; end;
When you are done, all of the query's logic will reside in the function named query_container. From now on, when you change query_container, you will change this and any other queries that reference it.
ref_67.rdf
.
Optional Exercise:
Repeat steps 1 through 19 for the other two queries in the report.
If you have many reports that use these same ref cursor types and SELECT statements, you can move the program units that you created into a PL/SQL library stored in a file or the database, so that other reports can easily share the code. The steps in this section will help you to move the program units to a PL/SQL library.
Tip: If the Live Previewer is open when you delete the packages from the report, you may get some errors.
.PLL
file extension. After you have found and selected PORT_CONTAINER, click Open.
Tip: If you get an error when you attempt to view the report, repeat steps 16 through 18.
ref_68.rdf
.
Optional Exercise:
Store the PL/SQL library in the database rather than in a file. Note that you will need "create" privileges on the database to complete this optional exercise.
Congratulations! You have finished the Ref Cursor Query sample report. You now know how to:
For more information about using ref cursors, see the online help:
|
|
Copyright © 1999 Oracle Corporation. All Rights Reserved. |
|