Está en la página 1de 8

Apex: Nested reports

Have you ever wondered how to display additional detail records together with the
master records in a single report?
For example, in a recent project I had to display a list of orders. Together with the
order details (who, when I had to display the order items in the same row.
The result should loo! li!e this"
How can this #e done?
The $tric!$ is to create a stored function which generates the HT%& for the detail
records so that they can #e displayed with the master records.
Here is a step #y step example #ased on the ta#les '%( and )'(T, what else *.
1. Create the package and stored function to generate the html for all
employees in a specific department:
CREATE OR REPLACE PACKAGE emp_pck
AS
/*********************************************************************
*********
NAME: EMP_PCK
PURPOSE:
REVISIONS:
Ver Date Aut!r De"cr#pt#!$
%%%%%%%%% %%%%%%%%%% %%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
&'( &)'(*'+((, &' Create- t#" packa.e'
**********************************************************************
********/
/UNCTION .et_emp"_#$0#$e_1 2p_-ept$! NUM3ER4
RETURN VARC5AR+6
END emp_pck6
/
CREATE OR REPLACE PACKAGE 3OD7 emp_pck
AS
/UNCTION .et_emp"_#$0#$e_1 2p_-ept$! NUM3ER4
RETURN VARC5AR+
IS
0_"tr VARC5AR+ 2*+,),46
0_c$t NUM3ER :8 (6
3EGIN
0_"tr :8 9:ta;0e c0a""8<#$0#$eTa;0e<=96
0_"tr :8
0_"tr
>>
9:tr=:t=N!':/t=:t=Name:/t=:t=?!;:/t=:t=Sa0ar@:/t=:/tr=96
/OR cur IN 2SELECT emp$!A e$ameA B!;A "a0
/ROM emp
C5ERE -ept$! 8 p_-ept$!
ORDER 37 e$ame4
LOOP
0_"tr :8 0_"tr >> 9:tr=96
0_"tr :8
0_"tr
>> 9:t-=9
>> cur'emp$!
>> 9:/t-=:t-=9
>> cur'e$ame
>> 9:/t-=:t-=9
>> cur'B!;
>> 9:/t-=:t-=9
>> cur'"a0
>> 9:/t-=96
0_"tr :8 0_"tr >> 9:/tr=96
0_c$t :8 0_c$t D &6
END LOOP6
0_"tr :8 0_"tr >> 9:/ta;0e=96
I/ 0_c$t 8 (
T5EN
RETURN 996
ELSE
RETURN 0_"tr6
END I/6
END6
END emp_pck6
/
2. Create the styles in the page header, in order to format the inline table:
:"t@0e t@pe8<teEt/c""<=
:F%%
'#$0#$eTa;0eG;!r-er:&pE "!0#- Hc1e(1&6;!r-er%
c!00ap"e:c!00ap"e6I#-t:&((J6K
'#$0#$eTa;0e tGc!0!r:H**))LL6;!r-er:&pE "!0#- Hc1e(1&6pa--#$.:+pE6K
'#$0#$eTa;0e t-G;!r-er:&pE "!0#- Hc1e(1&6;!r-er%0e1t:$!$e6;!r-er%
t!p:$!$e6pa--#$.:+pE6K
%%=
:/"t@0e=
3. Create the query in a report region
SELECT -ept'*A emp_pck'.et_emp"_#$0#$e_1 2-ept$!4 emp0!@ee"
/ROM -ept
Here you can see the final result:
The forum thread can #e found here and the online demo is located here.
+egards,
,)ietmar.
posted #y daust-de at .."/0 (%
10 Comments:
Patrick Wolf said...
That1s a nice one2 I have to add it to my !nowledge data#ase.
(atric!
3"45 6%

Denes Kubicek said...
'in sehr sch7nes 8eispiel )ietmar.
)enes
./"9: (%

J Miller said...
;ery nice example )ietmar. I1m sure that is a fairly common re<uirement.
=on.
:".5 6%

Maline said...
6 more generic method is to use a function that turns a ref cursor to an html
ta#le (example here. Then call the function while passing it a correlated
su#<uery within a cursor( call. I have further modified this example to use
a stored stylesheet so the function can use different stylesheets as needed.
5"/> (%

daust_de said...
Hi %aline,
interesting approach. I will post a full wor!ing sample later.
Than!s,
,)ietmar.
:".> 6%

Barry said...
)ietmar,
I am new to 6('? and very much enjoyed your #log on nested reports.
The report wor!s well if I want all departments. I assume from the function
argument that their is a way to limit output to a specific, single department,
#ut I am una#le to ma!e that wor!.
I thought there would #e a dynamic &@; somewhere in a search region to
limit the answer set. I must #e missing something.
Aour thoughts or any guidance is appricated.
8arry
4"B4 (%

daust_de said...
Hi 8arry,
nice that you enjoyed the (ost ".
I guess I don1t fully understand your <uestion.
The sample <uery I use lists all departments.
C'&'DT dept.E F+@% dept
In addition to that I display all employees in that specific department. I do
that for each row in the departments, this is why I use p-deptno as an input
parameter to the stored function.
If you want to limit the output to a specific department, you would limit the
#ase <uery"
C'&'DT dept.E F+@% dept
where deptnoF"p.-deptno
(.-)'(TG@ would #e a select list #ased on a lov.
or if you display a null value in the select list for showing all departments,
you could use the following"
C'&'DT dept.E F+@% dept
where ("p.-deptno is null or deptnoF"p.-deptno
6nd you would need a calculation for removing the HnullH from the select
list"
replace("p.-deptno, 1H1II1nullH1, null
Hope that helps. If you have more <uestions, feel free to as!.
+egards,
,)ietmar.
.0"45 6%

Anonymous said...
)ietmar,
This is very nice sample, very useful. However,
i am experiencing a pro#lem that the styles doesn1t wor! when i put it in the
page header.
Jhat could #e wrong?
Than!s,
=ennifer
4"/3 (%

daust_de said...
Hi =ennifer,
can you put up an example on apex.oracle.com? Then I can have a loo! at
it.
@r you can post your style definition and the source code of your function.
(lease encode the html tags, e.g. using this tool"
http"KKdaust.#logspot.comK0//5K/BKsmallLtoolLtoLescapeLhtmlLtextLfor.html
+egards,
,)ietmar.
3"// (%

Anonymous said...
Than! you. I am new to 6('? and this is a perfectly sensi#le solution to
displaying details. =oe C.
>"0B (%

(ost a Domment
Cu#scri#e to (ost Domments M6tomN
Links to this post:
Cee lin!s to this post
Dreate a &in!
OO Home

También podría gustarte