Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Model Clause - Group values

Christian BalzFeb 18 2009 — edited Nov 3 2010
Hi everybody,

Running the query below:
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bi
PL/SQL Release 10.2.0.3.0 - Production
CORE	10.2.0.3.0	Production
WITH TABLE_A AS (SELECT 1 ID, 'PRODUCT_A' PRODUCT FROM DUAL UNION ALL          
                 SELECT 2 ID, 'PRODUCT_2' PRODUCT FROM DUAL UNION ALL          
                 SELECT 1 ID, 'PRODUCT_B' PRODUCT FROM DUAL UNION ALL          
                 SELECT 1 ID, 'PRODUCT_D' PRODUCT FROM DUAL UNION ALL
                 SELECT 3 ID, 'PRODUCT_X' PRODUCT FROM DUAL UNION ALL
                 SELECT 1 ID, 'PRODUCT_C' PRODUCT FROM DUAL UNION ALL          
                 SELECT 3 ID, 'PRODUCT_Y' PRODUCT FROM DUAL UNION ALL                    
                 SELECT 1 ID, 'PRODUCT_A' PRODUCT FROM DUAL UNION ALL                    
                 SELECT 2 ID, 'PRODUCT_1' PRODUCT FROM DUAL UNION ALL                    
                 SELECT 1 ID, 'PRODUCT_A' PRODUCT FROM DUAL UNION ALL                    
                 SELECT 3 ID, 'PRODUCT_X' PRODUCT FROM DUAL UNION ALL                                     
                 SELECT 3 ID, 'PRODUCT_Z' PRODUCT FROM DUAL UNION ALL                                     
                 SELECT 2 ID, 'PRODUCT_2' PRODUCT FROM DUAL)
   SELECT ID, PRODUCT, TT_SUM, TOTAL
     FROM(SELECT ID, PRODUCT, COUNT(*) TT_SUM
            FROM TABLE_A
           GROUP BY ID, PRODUCT)
    MODEL 
DIMENSION BY(ID, PRODUCT)
 MEASURES (TT_SUM, 0 TOTAL)
    RULES (TOTAL[ANY, ANY] = SUM(TT_SUM) OVER (PARTITION BY ID ORDER BY PRODUCT))
    ORDER BY ID, PRODUCT
I would like to have the following result, with totals:
ID | PRODUCT   | TT_SUM | TOTAL
-------------------------------
1  | PRODUCT_A | 3      |  3
1  | PRODUCT_B | 1      |  4
1  | PRODUCT_C | 1      |  5
   | PRODUCT_D | 1      |  6
   | TOTAL     | 6      | 18

2  | PRODUCT_1 | 1      |  1
2  | PRODUCT_2 | 2      |  3
   | TOTAL     | 3      |  4

3  | PRODUCT_X | 2      |  2
3  | PRODUCT_Y | 1      |  3
3  | PRODUCT_Z | 1      |  4
   | TOTAL     | 4      |  9
How can I achieve this?

Tks in Advanced,

Christian Balz
This post has been answered by Solomon Yakobson on Feb 18 2009
Jump to Answer

Comments

PrafullaNath
I think there is no such command to trace a session.when ever a user gets connected to DB a session with sid,serial# gets associated with the user.

select sid,serial# from v$session where username='USER_NAME';

after that use

execute dbms_system.set_sql_trace_in_session(sid,serial#,true);

execute dbms_monitor.session_trace_enable(sid,serial#,true);
Pavan Kumar
Hi,
Enabling the trace to the user level
User level - its self reflects to Sessionw which it gets connected to ORACLE in order to Access the data/information.
Check with EXECUTE dbms_support.start_trace_in_session (9,29); else enable the trace @DB level for particular time and disable with out restart.

HTH

- Pavan Kumar N
- ORACLE OCP - 9i/10g
https://www.oracleinternals.blogspot.com
Aman....
I would not recommend to use DBMS_SUPPORT package since its not documented and is only meant for support. If you are on 10g and above, you can use DBMS_MONITOR package for the same.

HTH
Aman....
Pavan Kumar
Hi Aman,

Agree on that.. Sir... !! :-)

- Pavan Kumar N
DBA
Hi..Gurus,

thanks for the updates. I have used all these options earlier ,which were posted by you all, but sill i am not able to get the trace for spawned(child ) processes automatically. Only options is that i need to monitor closely v$session, and i need to enable the trace for each new spawned process, but it is very tedious job reason being my program takes approximately 5 hours to complete the entire job,


regards
DBA.
PrafullaNath
then better trace the entire instance/database
Hemant K Chitale
The procedure actually creates new sessions ? How and why ? How does it supply the SQLs to be executed by the child sessions ?

You could modify the code so that the SQL code it passes to the child session includes the DBMS_SESSION.START_TRACE call !



OR write a database LOGON trigger that enables tracing, based on the username.


Hemant K Chitale
1 - 7
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Mar 19 2009
Added on Feb 18 2009
12 comments
4,400 views