Skip to Main Content
  • Questions
  • Returning Sub Summary Report with Apex

Breadcrumb

Question and Answer

Tom Kyte

Thanks for the question, Mary.

Asked: January 09, 2008 - 9:35 am UTC

Last updated: May 14, 2012 - 1:26 am UTC

Version: 10.2.0.1

Viewed 1000+ times

You Asked

Hi Tom. I have an application written using apex 3.0.1 and oracle xe. I have a report that I am trying to create which I need to return a weekly work summary list by supported application.

I know how to do this using java and result sets but with apex, I am unsure of how to recreate this. I am using the "PL/SQL function body returning SQL query" for the type, within the report definition.

I would like the report to look similar to this --

******Report Begins***********
Peoplesoft Financials
1/2/08 Created new Demo Database
1/3/08 SQR Performance Issue in Production
1/4/08 Crystal Processes Hung in Process Scheduler

Peoplesoft HR
1/2/08 Created new Test Database
1/3/08 App Engine Performance Issue in Dev
1/4/08 Clear App Server Cache in Production
******Report Ends***************

The work items underneath each application are in one table with a foreign key relationship to the applications table.

Can you point me to an example or document for creating this kind of summary report with apex?

thanks!

and Tom said...

Ok, generally speaking, I'd need to know the details of the base tables - but I think I get it - you have a master/detail and want the master by itself, then details, then master/details and so on...

Hopefully, this is enough to get you going - if you group by grouping sets on

a) the row attributes
b) the master row attributes

you'll get that extra row and can use grouping() to null out the master elements

ops$tkyte%ORA10GR2> select dept.dname, emp.ename,
  2         grouping(dept.dname),
  3         grouping(emp.ename)
  4    from scott.dept, scott.emp
  5   where dept.deptno = emp.deptno
  6   group by grouping sets ((dept.dname,emp.ename),(dept.dname))
  7  /

DNAME          ENAME      GROUPING(DEPT.DNAME) GROUPING(EMP.ENAME)
-------------- ---------- -------------------- -------------------
SALES          WARD                          0                   0
SALES          ALLEN                         0                   0
SALES          BLAKE                         0                   0
SALES          JAMES                         0                   0
SALES          MARTIN                        0                   0
SALES          TURNER                        0                   0
SALES                                        0                   1
RESEARCH       FORD                          0                   0
RESEARCH       ADAMS                         0                   0
RESEARCH       JONES                         0                   0
RESEARCH       SCOTT                         0                   0
RESEARCH       SMITH                         0                   0
RESEARCH                                     0                   1
Accounting     KING                          0                   0
Accounting     CLARK                         0                   0
Accounting     MILLER                        0                   0
Accounting                                   0                   1

17 rows selected.

ops$tkyte%ORA10GR2> select dept.dname, emp.ename,
  2         grouping(dept.dname),
  3         grouping(emp.ename)
  4    from scott.dept, scott.emp
  5   where dept.deptno = emp.deptno
  6   group by grouping sets ((dept.dname,emp.ename),(dept.dname))
  7   order by dept.dname, grouping(emp.ename) DESC
  8  /

DNAME          ENAME      GROUPING(DEPT.DNAME) GROUPING(EMP.ENAME)
-------------- ---------- -------------------- -------------------
Accounting                                   0                   1
Accounting     MILLER                        0                   0
Accounting     CLARK                         0                   0
Accounting     KING                          0                   0
RESEARCH                                     0                   1
RESEARCH       ADAMS                         0                   0
RESEARCH       SMITH                         0                   0
RESEARCH       SCOTT                         0                   0
RESEARCH       JONES                         0                   0
RESEARCH       FORD                          0                   0
SALES                                        0                   1
SALES          ALLEN                         0                   0
SALES          WARD                          0                   0
SALES          BLAKE                         0                   0
SALES          MARTIN                        0                   0
SALES          JAMES                         0                   0
SALES          TURNER                        0                   0

17 rows selected.

ops$tkyte%ORA10GR2> select decode( grouping(emp.ename), 1,dept.dname, null) dname,
  2         emp.ename
  3    from scott.dept, scott.emp
  4   where dept.deptno = emp.deptno
  5   group by grouping sets ((dept.dname,emp.ename),(dept.dname))
  6   order by dept.dname, grouping(emp.ename) DESC
  7  /

DNAME          ENAME
-------------- ----------
Accounting
               MILLER
               CLARK
               KING
RESEARCH
               ADAMS
               SMITH
               SCOTT
               JONES
               FORD
SALES
               ALLEN
               WARD
               BLAKE
               MARTIN
               JAMES
               TURNER

17 rows selected.


Rating

  (4 ratings)

Is this answer out of date? If it is, please let us know via a Comment

Comments

great

Mary Wagner, January 10, 2008 - 8:16 am UTC

Thanks Tom! It works great.

Very nice!

Stew Ashton, January 10, 2008 - 3:21 pm UTC


A powerful capability that I am now dying to use, in a nice "thinking outside the box" example. Right up there with analytics and "connect by level".

Multiple Column Example

Mary Wagner, January 10, 2008 - 4:04 pm UTC

Just wanted to post this, it is not the entire sql that I used but it does include the multiple columns being returned underneath the master, in this case, APPLICATIONNAME.

SELECT DECODE(GROUPING(R.REQUESTID),1, A.APPLICATIONNAME, null) APPLICATIONNAME, R.DATEREQUESTED, R.REQUESTID, R.REQUESTTITLE 
FROM APPLICATIONS A, REQUESTS R 
WHERE R.APPLICATIONID=A.APPLICATIONID AND 
R.DBAID=15 AND(R.DATEREQUESTED >= TO_DATE('01-JAN-08', 'dd-mon-yy') AND R.DATEREQUESTED <= TO_DATE('07-JAN-08', 'dd-mon-yy')) 
group by grouping sets ((A.APPLICATIONNAME, R.DATEREQUESTED, R.REQUESTID, R.REQUESTTITLE),(A.APPLICATIONNAME)) 
order by A.APPLICATIONNAME, grouping(R.REQUESTID) DESC


*********RELATED TABLE DEFINITIONS**************
mwagner@XE> desc applications
 Name                                                  Null?    Type
 ----------------------------------------------------- -------- --------------
 APPLICATIONID                                         NOT NULL NUMBER(5)
 APPLICATIONTYPEID                                     NOT NULL NUMBER(5)
 APPLICATIONNAME                                       NOT NULL VARCHAR2(256)
 ALIAS                                                 NOT NULL VARCHAR2(50)
 CONTACTID                                             NOT NULL NUMBER(5)
 STATUSID                                              NOT NULL NUMBER(5)
 COMMENTS                                                       VARCHAR2(2048)
 USERSTAMP                                             NOT NULL VARCHAR2(16)
 DATESTAMP                                             NOT NULL DATE

mwagner@XE> desc requests
 Name                                                  Null?    Type
 ----------------------------------------------------- -------- --------------
 REQUESTID                                             NOT NULL NUMBER(9)
 PARENTREQUESTID                                       NOT NULL NUMBER(9)
 REQUESTTYPEID                                         NOT NULL NUMBER(3)
 REQUESTORID                                           NOT NULL NUMBER(5)
 DBAID                                                 NOT NULL NUMBER(5)
 PRIORITYID                                            NOT NULL NUMBER(2)
 APPLICATIONID                                         NOT NULL NUMBER(10)
 REQUESTSTATUSID                                       NOT NULL NUMBER(2)
 REQUESTTITLE                                          NOT NULL VARCHAR2(150)
 DATEREQUESTED                                         NOT NULL DATE
 DATENEEDED                                            NOT NULL DATE
 DATECOMPLETED                                                  DATE
 UPLOADFLAG                                            NOT NULL NUMBER(1)
 KNOWLEDGEBASEFLAG                                     NOT NULL NUMBER(1)
 AFTERHOURSFLAG                                        NOT NULL NUMBER(1)
 FOLLOWUPFLAG                                          NOT NULL NUMBER(1)
 REQUESTDETAILS                                        NOT NULL CLOB
 ROOTCAUSE                                                      CLOB
 SOLUTION                                                       CLOB
 USERSTAMP                                             NOT NULL VARCHAR2(16)
 DATESTAMP                                             NOT NULL DATE

crystal report

Anand, May 14, 2012 - 12:56 am UTC

Hi Tom,

We are using crystal report to generate report on daily basis which will execute function in oracle using CR oracle ODBC driver 5.0(DSN).

The question is how can i disable rule hint which uses by this DSN as in below query :

In other DSN like oracle in oradb10g_home1 have option to disable the hint rule.
If we remove the hint the query have good performance tuning.


Below is the query which execute by crystal every time we generate the report :

(select /*+ RULE */ a.owner,decode (b.object_type,'PACKAGE',concat(concat(b.object_name, '.'),a.object_name),b.object_name),
decode(a.position,0,'RETURN_VALUE',decode(a.argument_name,NULL,'UNKNOWN',a.argument_name)),
decode(a.position,0,5,decode(a.in_out,'IN',1,'IN/OUT',2,'OUT',4)),decode(a.data_type,'UNDEFINED',a.type_name,a.data_type),
a.data_precision,a.data_length,a.data_scale,a.radix,a.position
FROM ALL_ARGUMENTS a,dba_OBJECTS b WHERE (b.object_type IN ('PROCEDURE','FUNCTION','PACKAGE')) AND b.object_id=a.object_id AND a.data_level=0
AND a.owner like 'NCBSHOST'escape'\'AND b.OBJECT_NAME like 'AP_CI_R201'escape'\'
union all
select /*+ RULE */ c.owner,decode(b.object_type,'PACKAGE',CONCAT(CONCAT(c.synonym_name,'.'),a.object_name),c.synonym_name),
decode(a.position,0,'RETURN_VALUE',decode(a.argument_name,NULL,'UNKNOWN',a.argument_name)),decode(a.position,0,5,decode(a.in_out,'IN',1,'IN/OUT',2,'OUT',4)),
decode(a.data_type,'UNDEFINED',a.type_name,a.data_type),a.data_precision,a.data_length,a.data_scale,a.radix,a.position
FROM ALL_ARGUMENTS a,dba_OBJECTS b,dba_synonyms c
WHERE (c.table_owner=b.owner AND c.table_name=b.object_name) AND b.object_type IN ('PROCEDURE','FUNCTION','PACKAGE') AND b.object_id=a.object_id
AND a.data_level=0 AND c.owner like 'NCBSHOST'escape'\'AND c.synonym_NAME like 'AP_CI_R201'escape'\'
union all
select /*+ RULE */ c.owner,c.synonym_name,decode(a.position,0,'RETURN_VALUE',decode(a.argument_name,NULL,'UNKNOWN',a.argument_name)),
decode(a.position,0,5,decode(a.in_out,'IN',1,'IN/OUT',2,'OUT',4)),decode(a.data_type,'UNDEFINED',a.type_name,a.data_type),
a.data_precision,a.data_length,a.data_scale,a.radix,a.position
FROM ALL_ARGUMENTS a,dba_synonyms c WHERE (c.table_owner=a.package_name AND c.table_name=a.object_name)
AND a.data_level=0 AND c.owner like 'NCBSHOST'escape'\'AND c.synonym_NAME like 'AP_CI_R201'escape'\') order by 1,2,10;

Please help.

Tom Kyte
May 14, 2012 - 1:26 am UTC

In other DSN like oracle in oradb10g_home1 have option to disable the hint
rule.


that is news to me, I've never heard of being able to disable the single hint "rule".

In any case, maybe you can issue:

alter session set "_optimizer_ignore_hints" = true;

in the Crystal Report before executing the SQL?

ops$tkyte%ORA11GR2> set autotrace on explain
ops$tkyte%ORA11GR2> select /*+ RULE */ * from dual;

D
-
X


Execution Plan
----------------------------------------------------------
Plan hash value: 272002086

----------------------------------
| Id  | Operation         | Name |
----------------------------------
|   0 | SELECT STATEMENT  |      |
|   1 |  TABLE ACCESS FULL| DUAL |
----------------------------------

Note
-----
   - rule based optimizer used (consider using cbo)

ops$tkyte%ORA11GR2> alter session set "_optimizer_ignore_hints" = true;

Session altered.

ops$tkyte%ORA11GR2> select /*+ RULE */ * from dual;

D
-
X


Execution Plan
----------------------------------------------------------
Plan hash value: 272002086

--------------------------------------------------------------------------
| Id  | Operation         | Name | Rows  | Bytes | Cost (%CPU)| Time     |
--------------------------------------------------------------------------
|   0 | SELECT STATEMENT  |      |     1 |     2 |     2   (0)| 00:00:01 |
|   1 |  TABLE ACCESS FULL| DUAL |     1 |     2 |     2   (0)| 00:00:01 |
--------------------------------------------------------------------------

ops$tkyte%ORA11GR2> set autotrace off



the optimizer will ignore hints if you set that to true...