Rollup/Cube help

Hi,
Can anyone help me to get the following output with site-sub-total and grand-total within the one possible query: (I know it's possible either with Analytic function or new Group By Rollup/Cube functionality but do not know how to use them).
QUERY:
SELECT /*+ index(con con_start_end_i) */
con.id Contract,
con.property_id Property,
con.site_code,
con.ctyp_code,
con.crea_code,
con.purchase_price Puarchase_Amt,
con.commission_amount Comm_Amt,
con.start_date,
con.target_exchange_date,
con.target_completion_date,
con.empl_id,
con.sold_by
FROM
t_contracts con
WHERE
EXISTS ( SELECT 1 FROM t_employee_sites es WHERE es.emp_login_name = USER and es.site_code = con.site_code ) AND
con.empl_id LIKE '%' AND
NVL(con.sold_by,-1) = NVL(NULL, nvl(con.sold_by,-1)) AND
con.ctyp_code = 'SALE' AND
INSTR('WITHDRAW,PULL_OUT,', NVL(con.crea_code,'*')) = 0 AND
con.deleted IS NULL AND
(con.completed_date IS NULL OR con.completed_date > TO_DATE('13/06/2005', 'dd/mm/rrrr')) AND
con.start_date BETWEEN TO_DATE('13/06/2005', 'dd/mm/rrrr') and TRUNC(SYSDATE)
ORDER BY
con.site_code;
Sample Output:
Please find the following sample output:
Contract, Property, Crea_Code, Purchase_Amt, Comm_Amt, Start_Date, Sold_By
Site: <Site_Code1>
xxxx xxxx xxxx 9,999,999.99 9,999,999.99 dd/mm/yyyy xx
xxxx xxxx xxxx 9,999,999.99 9,999,999.99 dd/mm/yyyy xx
Total for Site: <Site_Code1> <Site1_Pur> <Site1_Comm>
No of Property: <Site1_Count>
Site: <Site_Code2>
xxxx xxxx xxxx 9,999,999.99 9,999,999.99 dd/mm/yyyy xx
xxxx xxxx xxxx 9,999,999.99 9,999,999.99 dd/mm/yyyy xx
Total for Site: <Site_Code2> <Site2_Pur> <Site2_Comm>
No of Property: <Site2_Count>
Total: <Tot_Pur> <Tot_Comm>
Total Property: <Tot_Count>
Your help would appreciate to sort this out asap....
Kind Regards,
B Tanna
London
UK

Hi Riedelme,
Thanks for your reply. Further to your reply I go through Group By functionality. I tried the different ways and found the solution. I have to use
GROUP BY GROUPING SETS(con.site_code, (con.site_code, con.id, con.property_id, con.ctyp_code, con.crea_code, con.start_date, con.target_exchange_date, con.target_completion_date, con.empl_id, con.sold_by), ())But now my worry is what happens if number of column grows, say, 35. There should be some way of writing good query. Would it be possible using Analytic Function.
Experts please respond..

Similar Messages

  • To Rick Post about cross-tabulation, rollup, cube

    Rick,
    One of the systems that I have access to has just been upgraded to Oracle8i Enterprise Edition Release 8.1.6.3.0 and SQL*Plus: Release 8.0.6.0.0. So, after doing many things the hard way for a long time, I am just beginning to experiment with some of the new features that I have been reading about, like cross-tabulation with rollup and cube in the group by clause.
    In the four posts listed below, where I provided solutions using decode, you have said that the desired cross-tabular result could be achieved using rollup and cube in the group by clause, but you have not provided any sample code. I have read the documentation, but am still unable to figure out how to achieve the same results. I am not receiving any error messages; I am just not figuring out how to achieve the same results. Would you please do me the favor of providing the code using rollup and cube that will produce the same results as the code I have offered, for any of the posts below?
    http://technet.oracle.com:89/ubb/Forum88/HTML/000134.html
    http://technet.oracle.com:89/ubb/Forum88/HTML/000428.html
    http://technet.oracle.com:89/ubb/Forum88/HTML/000494.html
    http://technet.oracle.com:89/ubb/Forum88/HTML/000722.html
    I have really enjoyed reading your posts and learned a lot from them and look forward to your response.
    Thank you,
    Barbara
    null

    Dear Raju,
    1) Does it mean parent level members will be calculated every time it is retrieved from BPC.
    2) by "user hierarchy in Bex", does it mean to "Activate Hierarchy display in Query Designer?
    or u mean select the hierarchy tree when building query as shown below?
    Thanks for your help.
    Regards,
    Winson

  • Rollup/Cube Operation in Oracle 10g

    I'm using Oracle 10g as my database.
    Suppose I have a table that has data:
    ID SEMESTER SUBJECT MARKS
    9 4 Maths 50
    9 4 Science 45
    9 4 English 42
    10 5 Maths 56
    10 5 History 23
    Now the output should look like this
    ID SEMESTER SUBJECT MARKS RANK
    9 4 Maths 50
    Science 45
    English 42
    Total 137 1
    10 5 Maths 56
    History 23
    Total 79 2
    Can anybody please help me out.
    Thanx in advance

    Select * from tmp_sp_marks
    SEMESTER     SUBJECT     MARKS          STUDID
    3          Maths          40          8
    3          English     52          8
    3          ujarati          40          8
    4          Science     45          9
    4          English     42          9
    5          Maths          43          10
    5          English     44          10
    4          Maths          50          9
    select case when rn = 1 then studid else null end studid,
    case when rn = 1 then semester else null end semester,
    subject,
    marks,
    case when subject = 'Total' then rank else null end rank
    from
    select studid, semester, subject, marks, max(rank) over(partition by studid, semester) rank,
    row_number() over(partition by studid, semester order by marks) rn
    from
    select studid, semester, subject, marks, 0 rank from tmp_sp_marks a
    union
    select studid, semester, 'Total', sm, dense_rank() over(order by sm desc) rank
    from (
    select studid, semester, sum(marks) sm
    from tmp_sp_marks
    group by rollup(studid, semester) )
    where studid is not null and semester is not null
    order by max(rank) over(partition by studid, semester) desc , marks asc
    OUTPUT:
    STUDID     SEMESTER     SUBJECT     MARKS          RANK
    8          3     Maths     40     
                   Gujarati     40     
              English     52     
              Total     132          2
    9          4     English     42     
              Science     45     
              Maths     50     
              Total     137          1
    10          5     Maths     43     
              English     44     
              Total     87          3

  • How to rollup cube data in Process chain?

    I have loaded data into a cube, and when i look at the technical status it is green but there is nothing in the "request for reporting available"box. I went to Rollup Tab and manually execute the request. It worked.
    But is there anyway that I can add a process type to do it automatically? I saw there are three process type related to Rollup, which one should I use?
    1. Initial Fill of New Aggregates
    2. Roll Up of Filled Aggregates/BIA Indexes (what does this mean?)
    3. initial Activation and Filling of BIA Indexes
    Thank you!

    Dear experts,
    We have the following problem: for certain figures we have on ODS level 2 daily updates: one at night and one at noon. During the week at noon we only load from the ODS into the Cubes only that data that is entered the same day (selection on CPU-Date in the InfoPackage). After loading the data at night we load the data which was entered the previous day (selection on CPU-Date in the InfoPackage). In this process we have a step in the process chain that deletes in the overlapping request of the previous day (which was loaded at noon).
    Our Process Chain for loading the data from ODS into the cubes looks as following:
    Delete Indexes of the cubes -> Load data from ODS into Cubes -> Generate Cube Indexes -> Delete overlapping Requests in InfoCubes
    After filling the BIA-Indexes on this cube, the process chain gives an error message at the stage where the overlapping request should be deleted.  The error messages says:
    Uncaught Exception: Keyfigure is of type Float.
    To solve this error at the moment we manually delete the BIA Indexes, delete the overlapping requests and fill the BIA Indexes again. Since the functions 'delete BIA Index' and 'Fill BIA Index' is not available in RSPC we can not do this automatically in the process chain.
    I also tried like above mentioned taking the step 'roll up filled BIA Indexes' into the process chain, but the check of the process chain creates a message stating that i cannot do this when in the same process chain the steps 'Delete Indexes of the Cube' and 'generate Indexes of the cubes' are included.
    Does anybody know a solution how i can delete overlapping requests in a process chain with filled BIA Indexes.
    Many thanks in advance for your kind reply.
    Best regards,
    Ilja Dekeyser

  • Analytical functions-ROLLUP&CUBE

    Hi,
    Can anyone give me a clear explanation on the 2 analytical fns rollup and cube?I'm finding it a bit confusing.
    Thanks in advance,
    Sudarshan.S

    http://asktom.oracle.com/pls/ask/f?p=4950:8:3940765887821547038::NO::F4950_P8_DISPLAYID,F4950_P8_CRITERIA:1512805503041

  • ROLLUP & CUBE GROUP FUNCTION

    can anybody explain the functionality of ROLLUP and CUBE functions in oracle9i

    Lets do us all a favor and use current docs (that is < 11g which is still too new for most)
    http://www.oracle.com/pls/db102/homepage

  • RollUp & Cube.

    <SQL> Connect Scott/Tiger
    Connected.
    <SQL> Select Deptno,
    2 Decode(Ename,Null,'T O T A L',Ename),
    3 SUM(Sal)
    4 From Emp
    5 Group By ROLLUP(Deptno,Ename);
    DEPTNO DECODE(ENA SUM(SAL)
    10 AWAIS 5000
    10 CLARK 2450
    10 MILLER 1300
    10 T O T A L 8750
    20 23132121 1000
    20 ADAMS 1100
    20 FORD 3000
    20 JONES 2975
    20 SCOTT 3000
    20 SMITH 800
    20 T O T A L 11875
    30 ALLEN 1600
    30 BLAKE 2850
    30 JAMES 950
    30 MARTIN 1250
    30 TURNER 1500
    30 WARD 1250
    30 T O T A L 9400
    T O T A L 30025
    19 rows selected.
    RollUp Functionality is Perfect.
    But what is this ?
    SQL> Select Deptno,
    2 Decode(Ename,Null,'T O T A L',Ename),
    3 SUM(Sal)
    4 From Emp
    5 Group By CUBE(Deptno,Ename);
    DEPTNO DECODE(ENA SUM(SAL)
    10 AWAIS 5000
    10 CLARK 2450
    10 MILLER 1300
    10 T O T A L 8750
    20 23132121 1000
    20 ADAMS 1100
    20 FORD 3000
    20 JONES 2975
    20 SCOTT 3000
    20 SMITH 800
    20 T O T A L 11875
    30 ALLEN 1600
    30 BLAKE 2850
    30 JAMES 950
    30 MARTIN 1250
    30 TURNER 1500
    30 WARD 1250
    30 T O T A L 9400
    23132121 1000
    ADAMS 1100
    ALLEN 1600
    DEPTNO DECODE(ENA SUM(SAL)
    AWAIS 5000
    BLAKE 2850
    CLARK 2450
    FORD 3000
    JAMES 950
    JONES 2975
    MARTIN 1250
    MILLER 1300
    SCOTT 3000
    SMITH 800
    TURNER 1500
    WARD 1250
    T O T A L 30025
    34 rows selected.
    Cube is Selecting 34 Rows, Why ?
    I am not understanding the functionalilty of Cube.
    Can any one define it ?
    Thanks in Advance...

    Hi,
    With cube, you create subtotals in different dimension. Your example does not make sense for cube, since ename is unique for all departments.
    Look at this. Also note the "GROUPING" function, which distinguish pure null values and null because of grouping (giving 1).
    Kind regards
    Laurent Schneider
    OCM-DBA
    select decode(grouping(JOB), 1, 'T O T A L', job) JOB,
    decode(grouping(DNAME), 1, 'T O T A L', dname) DNAME,
    sum(nvl(sal,0))
    from emp natural full outer join dept
    group by cube(job,dname)
    order by 1 nulls first, 2 nulls first;
    JOB       DNAME          SUM(NVL(SAL,0))
              OPERATIONS                   0
              T O T A L                    0
    ANALYST   RESEARCH                  6000
    ANALYST   T O T A L                 6000
    CLERK     ACCOUNTING                1300
    CLERK     RESEARCH                  1900
    CLERK     SALES                      950
    CLERK     T O T A L                 4150
    MANAGER   ACCOUNTING                2450
    MANAGER   RESEARCH                  2975
    MANAGER   SALES                     2850
    MANAGER   T O T A L                 8275
    PRESIDENT ACCOUNTING                5000
    PRESIDENT T O T A L                 5000
    SALESMAN  SALES                     5600
    SALESMAN  T O T A L                 5600
    T O T A L ACCOUNTING                8750
    T O T A L OPERATIONS                   0
    T O T A L RESEARCH                 10875
    T O T A L SALES                     9400
    T O T A L T O T A L                29025

  • Query related to the group by rollup,cube

    Hello experts,
    I am not getting how the below query gets excuted ,
    {code}
    SELECT department_id,   job_id,   manager_id,   SUM(salary) FROM employess GROUP BY department_id,   ROLLUP(job_id),   CUBE(manager_id)
    {code}
    can anybody simplified this plz ?
    Thanks in advance

    Hi,
    SShubhangi wrote:
    Hello experts,
    I am not getting how the below query gets excuted ,
    {code}
    SELECT department_id,   job_id,   manager_id,   SUM(salary) FROM employess GROUP BY department_id,   ROLLUP(job_id),   CUBE(manager_id)
    {code}
    can anybody simplified this plz ?
    Thanks in advance
    Here's how it works.
    Since the GROUP BY clause includes department_id (not modified by ROLLUP or CUBE), every row of the result set will be limited to a specific department_id.
    Since the GROUP BY clause includes ROLLUP (job_id). some rows of the result set will represent a specific job_id, and some rows will be Super-Aggregate rows, representing all job_ids at the same time.
    Since the GROUP BY clause includes CUBE (manager_id). some rows of the result set will represent a specific manage_id, and some rows will be super-aggregates, representing all manager_ids at the same time.  (When there is only 1 expression inside the parentheses, CUBE means the same thing as ROLLUP).
    Here's how it can be simplified:
    GROUP BY  department_id
    ,         CUBE (job_id, manager_id)
    Here's why:
    Since ROLLUP (x) means the same thing as CUBE (x) - when x is a single expression - then what you posted is equivalent to
    GROUP BY  department_id
    ,         CUBE (job_id)
    ,         CUBE (manager_id)
    and
    GROUP BY  ...
              CUBE (x)
    ,         CUBE (y)
    is just a longer way of saying
    GROUP BY  ...
              CUBE (x, y)
    To understand this better, do some experiments yourself.  Try different combinations of ROLLUP and CUBE, and see what results they produce.
    DO NOT use the hr.employees table for your experiments; it has far too many groups for anyone to understand. Also, department_id and manager_id can be NULL, so it's hard to tell super-aggregate rows from normal aggregate rows.  Even scott.emp is more complicated than necessary.  I suggest you make your own table, like this:
    CREATE TABLE  simp_emp  AS
    SELECT  ename
    ,       deptno
    ,       job
    ,       CASE
                WHEN  job IN ('MANAGER', 'PRESIDENT')
                THEN  'NO'
                ELSE  'YES'
            END                            AS unionized
    ,       EXTRACT (YEAR FROM hiredate)   AS hireyear
    ,       sal
    FROM    scott.emp
    In this table, there are only 2 possible values for unionized, 3 values for deptno, and 4 values for hireyear, and none of those colums are ever NULL.

  • SD Cubes Help Needed

    Dear All,
    Can someone explain to me why the cubes (0SD_C01 - 0SD_C05) use extractors like 2LIS_01_S***?
    When I am using a customer cube 0sd_c01 i have to use the 2lis_01_S001. All the dimensions present in that cube are also present in 0sd_c05 which is offers cube. Do we at all need to use the cube 0sd_c01.If yes please explain me the scenario where this could be indispensible.
    In our implementations we used both the cubes and I am trying to understand the use of that cube which uses lis structure.
    Thanks,
    Pavan.

    Pavan,
    0SD_C05 is mainly focused to the quotation analysis and, as you can see from this help page, potential info are completely different from the simple customer analysis you can do with 0SD_C01:
    http://help.sap.com/saphelp_nw2004s/helpdata/en/21/93e63736544d4de10000009b38f8cf/content.htm
    Hope it helps!
    Bye,
    Roberto

  • Need Cube help. can't re-install OS.

    A friend bought a Cube on eBay. It came with no disks. It only has a user account. No admin account. So I figured to just wipe computer using 10.4 install cd. 10.4.11 is installed on the computer.
    We don't have an admin name or password.
    Every time I insert the install cd, it is rejected. If I restart and hold down the C key, the computer will not boot from it.
    Is there anyway to force the computer into starting from CD? Sort a recovery mode so I can wipe the drive and reinstall?
    I can't create other accounts because no admin privileges.
    I'm lost on this one.
    Thanks

    Keyboard is wired.
    So here is what I did after all failed.
    I used Carbon Copy Cloner to copy the install CD to an external Firewire Drive.
    Booted the Cube with the Option key down. The FireWire came up. Booted from the install copy on the FW drive. Wiped the Cube and reinstalled.
    This was my last resort because all my extra drives are formated GUID and full. So I had to move so much around. Reformat, Clone. The hours I was trying to avoid.
    I thank all for the help. But I got it and now just running all the updates.
    The good thing about this is? This is a friend that is a die hard PC guy. He wanted to try a Mac so he bought a Cube on eBay. He fell in love with this thing last night. So add another convert to Apple.

  • ROLLUP AND CUBE OPERATORS IN ORACLE 8I

    제품 : PL/SQL
    작성날짜 : 2000-06-29
    ========================================
    ROLLUP AND CUBE OPERATORS IN ORACLE 8I
    ========================================
    PURPOSE
    ROLLUP 과 CUBE Operator에 대해 설명하고자 한다.
    Explanation
    ROLLUP operator는 SELECT문의 GROUP BY절에 사용된다.
    SELECT절에 ROLLUP 을 사용함으로써 'regular rows'(보통의 select된 data)와
    'super-aggregate rows'(총계)을 구할 수 있다. 기존에는 select ... union select
    를 이용해 구사해야 했었던 것이다. 'super-aggregate rows'는 'sub-total'
    (중간 Total, 즉 소계)을 포함한다.
    CUBE operator는 Cross-tab에 대한 Summary를 추출하는데 사용된다. 모든 가능한
    dimension에 대한 total을 나타낸다. 즉 ROLLUP에 의해 나타내어지는 item total값과
    column total값을 나타낸다.
    NULL값은 모든 값에 대한 super-aggregate 을 나타낸다. GROUPING() function은
    모든 값에 대한 set을 나타내는 null값과 column의 null값과 구별하는데 쓰여진다.
    GROUPING() function은 GROUP BY절에서 반드시 표현되어야 한다. GROUPING()은 모든
    값의 set을 표현합에 있어서 null이면 1을 아니면 0을 return한다.
    ROLLUP과 CUBE는 CREATE MATERIALIZED VIEW에서 사용되어 질수 있다.
    Example
    아래와 같이 테스트에 쓰여질 table과 data을 만든다.
    create table test_roll
    (YEAR NUMBER(4),
    REGION CHAR(7),
    DEPT CHAR(2),
    PROFIT NUMBER );
    insert into test_roll values (1995 ,'West' , 'A1' , 100);
    insert into test_roll values (1995 ,'West' , 'A2' , 100);
    insert into test_roll values (1996 ,'West' , 'A1' , 100);
    insert into test_roll values (1996 ,'West' , 'A2' , 100);
    insert into test_roll values (1995 ,'Central' ,'A1' , 100);
    insert into test_roll values (1995 ,'East' , 'A1' , 100);
    insert into test_roll values (1995 ,'East' , 'A2' , 100);
    SQL> select * from test_roll;
    YEAR REGION DE PROFIT
    1995 West A1 100
    1995 West A2 100
    1996 West A1 100
    1996 West A2 100
    1995 Central A1 100
    1995 East A1 100
    1995 East A2 100
    7 rows selected.
    예제 1: ROLLUP
    SQL> select year, region, sum(profit), count(*)
    from test_roll
    group by rollup(year, region);
    YEAR REGION SUM(PROFIT) COUNT(*)
    1995 Central 100 1
    1995 East 200 2
    1995 West 200 2
    1995 500 5
    1996 West 200 2
    1996 200 2
    700 7
    7 rows selected.
    위의 내용을 tabular로 나타내어 보면 쉽게 알 수 있다.
    Year Central(A1+A2) East(A1+A2) West(A1+A2)
    1995 (100+NULL) (100+100) (100+100) 500
    1996 (NULL+NULL) (NULL+NULL) (100+100) 200
    700
    예제 2: ROLLUP and GROUPING()
    SQL> select year, region, sum(profit),
    grouping(year) "Y", grouping(region) "R"
    from test_roll
    group by rollup (year, region);
    YEAR REGION SUM(PROFIT) Y R
    1995 Central 100 0 0
    1995 East 200 0 0
    1995 West 200 0 0
    1995 500 0 1
    1996 West 200 0 0
    1996 200 0 1
    700 1 1
    7 rows selected.
    참고) null값이 모든 값의 set에 대한 표현으로 나타내어지면 GROUPING function은
    super-aggregate row에 대해 1을 return한다.
    예제 3: CUBE
    SQL> select year, region, sum(profit), count(*)
    from test_roll
    group by cube(year, region);
    YEAR REGION SUM(PROFIT) COUNT(*)
    1995 Central 100 1
    1995 East 200 2
    1995 West 200 2
    1995 500 5
    1996 West 200 2
    1996 200 2
    Central 100 1
    East 200 2
    West 400 4
    700 7
    위의 내용을 tabular로 나타내어 보면 쉽게 알 수 있다.
    Year Central(A1+A2) East(A1+A2) West(A1+A2)
    1995 (100+NULL) (100+100) (100+100) 500
    1996 (NULL+NULL) (NULL+NULL) (100+100) 200
    100 200 400 700
    예제 4: CUBE and GROUPING()
    SQL> select year, region, sum(profit),
    grouping(year) "Y", grouping(region) "R"
    from test_roll
    group by cube (year, region);
    YEAR REGION SUM(PROFIT) Y R
    1995 Central 100 0 0
    1995 East 200 0 0
    1995 West 200 0 0
    1995 500 0 1
    1996 West 200 0 0
    1996 200 0 1
    Central 100 1 0
    East 200 1 0
    West 400 1 0
    700 1 1
    10 rows selected.
    ===============================================
    HOW TO USE ROLLUP AND CUBE OPERATORS IN PL/SQL
    ===============================================
    Release 8.1.5 PL/SQL에서는 CUBE, ROLLUP 이 지원되지 않는다. 8i에서는 DBMS_SQL
    package을 이용하여 dynamic SQL로 구현하는 방법이 workaround로 제시된다.
    Ordacle8i에서는 PL/SQL block에 SQL절을 직접적으로 위치시키는 Native Dynamic SQL
    (참고 bul#11721)을 지원한다.
    Native Dynamic SQL을 사용하기 위해서는 COMPATIBLE 이 8.1.0 또는 그 보다 높아야
    한다.
    SVRMGR> show parameter compatible
    NAME TYPE VALUE
    compatible string 8.1.0
    예제 1-1: ROLLUP -> 위의 예제 1과 비교한다.
    SQL> create or replace procedure test_rollup as
    my_year test_roll.year%type;
    my_region test_roll.region%type;
    my_sum int;
    my_count int;
    begin
    select year, region, sum(profit), count(*)
    into my_year, my_region, my_sum, my_count
    from test_roll
    group by rollup(year, region);
    end;
    Warning: Procedure created with compilation errors.
    SQL> show errors
    Errors for PROCEDURE TEST_ROLLUP:
    LINE/COL ERROR
    10/8 PL/SQL: SQL Statement ignored
    13/18 PLS-00201: identifier 'ROLLUP' must be declared
    SQL> create or replace procedure test_rollup as
    type curTyp is ref cursor;
    sql_stmt varchar2(200);
    tab_cv curTyp;
    my_year test_roll.year%type;
    my_region test_roll.region%type;
    my_sum int;
    my_count int;
    begin
    sql_stmt := 'select year, region, sum(profit), count(*) ' ||
    'from test_roll ' ||
    'group by rollup(year, region)';
    open tab_cv for sql_stmt;
    loop
    fetch tab_cv into my_year, my_region, my_sum, my_count;
    exit when tab_cv%NOTFOUND;
    dbms_output.put_line (my_year || ' '||
    nvl(my_region,' ') ||
    ' ' || my_sum || ' ' || my_count);
    end loop;
    close tab_cv;
    end;
    SQL> set serveroutput on
    SQL> exec test_rollup
    1995 Central 100 1
    1995 East 200 2
    1995 West 200 2
    1995 500 5
    1996 West 200 2
    1996 200 2
    700 7
    PL/SQL procedure successfully completed.
    예제 2-1: ROLLUP and GROUPING() -> 위의 예제 2와 비교한다.
    SQL> create or replace procedure test_rollupg as
    my_year test_roll.year%type;
    my_region test_roll.region%type;
    my_sum int;
    my_count int;
    my_g_region int;
    my_g_year int;
    begin
    select year, region, sum(profit),
    grouping(year), grouping(region)
    into my_year, my_region, my_sum, my_count,
    my_g_year, my_g_region
    from test_roll
    group by rollup(year, region);
    end;
    Warning: Procedure created with compilation errors.
    SQL> show error
    Errors for PROCEDURE TEST_ROLLUPG:
    LINE/COL ERROR
    12/4 PL/SQL: SQL Statement ignored
    17/13 PLS-00201: identifier 'ROLLUP' must be declared
    SQL> create or replace procedure test_rollupg as
    type curTyp is ref cursor;
    sql_stmt varchar2(200);
    tab_cv curTyp;
    my_year test_roll.year%type;
    my_region test_roll.region%type;
    my_sum int;
    my_count int;
    my_g_region int;
    my_g_year int;
    begin
    sql_stmt := 'select year, region, sum(profit), count(*), ' ||
    'grouping(year), grouping(region) ' ||
    'from test_roll ' ||
    'group by rollup(year, region)';
    open tab_cv for sql_stmt;
    loop
    fetch tab_cv into my_year, my_region, my_sum, my_count,
    my_g_year, my_g_region;
    exit when tab_cv%NOTFOUND;
    dbms_output.put_line (my_year || ' '||my_region ||
    ' ' || my_sum || ' ' || my_count ||
    ' ' || my_g_year || ' ' || my_g_region);
    end loop;
    close tab_cv;
    end;
    Procedure created.
    SQL> set serveroutput on
    SQL> exec test_rollupg
    1995 Central 100 1 0 0
    1995 East 200 2 0 0
    1995 West 200 2 0 0
    1995 500 5 0 1
    1996 West 200 2 0 0
    1996 200 2 0 1
    700 7 1 1
    PL/SQL procedure successfully completed.
    예제 3-1: CUBE -> 위의 예제 3과 비교한다.
    SQL> create or replace procedure test_cube as
    my_year test_roll.year%type;
    my_region test_roll.region%type;
    my_sum int;
    my_count int;
    begin
    select year, region, sum(profit), count(*)
    into my_year, my_region, my_sum, my_count
    from test_roll
    group by cube(year, region);
    end;
    Warning: Procedure created with compilation errors.
    SQL> show error
    Errors for PROCEDURE TEST_CUBE:
    LINE/COL ERROR
    10/4 PL/SQL: SQL Statement ignored
    13/13 PLS-00201: identifier 'CUBE' must be declared
    SQL> create or replace procedure test_cube as
    type curTyp is ref cursor;
    sql_stmt varchar2(200);
    tab_cv curTyp;
    my_year test_roll.year%type;
    my_region test_roll.region%type;
    my_sum int;
    my_count int;
    begin
    sql_stmt := 'select year, region, sum(profit), count(*) ' ||
    'from test_roll ' ||
    'group by cube(year, region)';
    open tab_cv for sql_stmt;
    loop
    fetch tab_cv into my_year, my_region, my_sum, my_count;
    exit when tab_cv%NOTFOUND;
    dbms_output.put_line (my_year || ' '||
    nvl(my_region,' ') ||
    ' ' || my_sum || ' ' || my_count);
    end loop;
    close tab_cv;
    end;
    Procedure created.
    SQL> set serveroutput on
    SQL> exec test_cube
    1995 Central 100 1
    1995 East 200 2
    1995 West 200 2
    1995 500 5
    1996 West 200 2
    1996 200 2
    Central 100 1
    East 200 2
    West 400 4
    700 7
    PL/SQL procedure successfully completed.
    예제 4-1: CUBE and GROUPING() -> 위의 예제 4와 비교한다.
    SQL> create or replace procedure test_cubeg as
    my_year test_roll.year%type;
    my_region test_roll.region%type;
    my_sum int;
    my_count int;
    my_g_region int;
    my_g_year int;
    begin
    select year, region, sum(profit),
    grouping(year), grouping(region)
    into my_year, my_region, my_sum, my_count,
    my_g_year, my_g_region
    from test_roll
    group by cube(year, region);
    end;
    Warning: Procedure created with compilation errors.
    SQL> show error
    Errors for PROCEDURE TEST_CUBEG:
    LINE/COL ERROR
    12/4 PL/SQL: SQL Statement ignored
    17/13 PLS-00201: identifier 'CUBE' must be declared
    SQL> create or replace procedure test_cubeg as
    type curTyp is ref cursor;
    sql_stmt varchar2(200);
    tab_cv curTyp;
    my_year test_roll.year%type;
    my_region test_roll.region%type;
    my_sum int;
    my_count int;
    my_g_region int;
    my_g_year int;
    begin
    sql_stmt := 'select year, region, sum(profit), count(*), ' ||
    'grouping(year), grouping(region) ' ||
    'from test_roll ' ||
    'group by cube(year, region)';
    open tab_cv for sql_stmt;
    loop
    fetch tab_cv into my_year, my_region, my_sum, my_count,
    my_g_year, my_g_region;
    exit when tab_cv%NOTFOUND;
    dbms_output.put_line (my_year || ' '||my_region ||
    ' ' || my_sum || ' ' || my_count ||
    ' ' || my_g_year || ' ' || my_g_region);
    end loop;
    close tab_cv;
    end;
    Procedure created.
    SQL> set serveroutput on
    SQL> exec test_cubeg
    1995 Central 100 1 0 0
    1995 East 200 2 0 0
    1995 West 200 2 0 0
    1995 500 5 0 1
    1996 West 200 2 0 0
    1996 200 2 0 1
    Central 100 1 1 0
    East 200 2 1 0
    West 400 4 1 0
    700 7 1 1
    PL/SQL procedure successfully completed.
    Reference Ducumment
    Note:67988.1

    Hello,
    As previously posted you should use export and import utilities.
    To execute exp or imp statements you have just to open a command line interface, for instance,
    a DOS box on Windows.
    So you don't have to use SQL*Plus or TOAD.
    About export/import you may care on the mode, to export a single or a list of Tables the Table mode
    is enough.
    Please, find here an example to begin:
    http://wiki.oracle.com/page/Oracle+export+and+import+
    Hope this help.
    Best regards,
    Jean-Valentin

  • Roll up command and CUBE command

    Please anyone explain me what is the use of ROLLUP and CUBE command in SQL and which situations it will be using.

    Rollup and cube, both of these will be helpfull in aggregate function along with group by.
    Roll up will results in data along with their summation.
    and Cube results in summation of all possible combination.
    It will be help when creating reports and some analytical data.
    Below is an article which give further more explanation
    http://www.oracle-base.com/articles/misc/rollup-cube-grouping-functions-and-grouping-sets.php

  • How use Group By Rollup in BIP ?

    Hy everybody ,
    I create a dataset with this query :
    SELECT  cntr.country_region "Region" , cntr.country_name  "Pay ", Round(AVG(s.quantity_sold * s.amount_sold ),2) "Moyenne Des Ventes"
    FROM customers c inner join sales s
    on c.cust_id = s.cust_id
    inner join countries cntr
    on c.country_id =  cntr.country_id
    group by rollup (cntr.country_region,cntr.country_name )
    It's ok in ad-hoc mode , it's ok when i generate sample data , but when i want to create my Report : I use "Data Table" and for the "Moyenne Des Ventes" column , i have no data.
    Someone can help me ?

    "ROLLUP",  "CUBE",  "GROUPING SETS" actually I used for ad-hoc reporting only on text based tools. Though in report development tools you can easily generate sub-totals I think you can use different queries.

  • In need help: Analytic Report with Group by

    Good morning,
    I am trying to create a report with subtotal and grand total, which of couse goes to the group by clause, with rollup, cube, grouping... etc. I'd like to use rollup, then some columns in the Select list have to be put into the Group By clause, which is not supposed to be. So I had to use one of SUM, AVG, MIN and MAX functions, to make those columns as *aggregated, which is wrong.
    Another alternative I tried is to use Cube and Grouping_id to be the filter. However, that is still very cumbentsome and error-prone, also the order of the display is absolutely out of control.
    I am trying hard to stick to the first option of using the Rollup, since the result is very close to what I want, but avoid the usage of aggregation functions. For example, if I want to display column A, which should not be grouped. Other than using those aggregation functions, what I can do?
    Thanks in advance.

    Luc,
    this is a simple and a good reference for analytic functions:
    http://www.orafaq.com/node/55
    It takes some time to understand how they work and also it takes some time to understand how to utilize them. I have solved some issues in reporting using them, avoiding the overkill of aggregates.
    Denes Kubicek

  • DELTA AND INIT TO CUBE Simple

    Please help me with this, I have a bad red delta request coming from billing ods  in bmw cube so i deleted the request, but bmw cube has other green  request coming from order and delivery which is fine green and success.
    now to resolve this i deleted the red delta request of billing  and also deleted every thing from ods and i redo the set up table and did init to billing ods but now when init goes to bmw cube it fails please tell me the exact step to resolve this please tell me how can i set up the delta again so that init from billing ods goes to cube
    help me with navigation step.i do not want to delete the entire data from cube to resolve this
    thanks
    soniya
    soniya

    Let me try to get it.
    Your ODS has delta coming in for a specific fiscal period? Is there no overlap (meaning one billing document coming in as new into the ODS and cube is not changed in the next period)?
    If not, there may be a problem.
    Consider the case where you had a document which came in earlier (successful) request, and is there in the cube (say with a original qty of 25). Now, say your last delta had a change to it (of qty increased by 5, say), and this delta failed to go to the cube. Now you are doing a full load with repair for this period.
    Since you are doing a full load, it will bring a qty of 30; however your cube has the earlier record (with a value 25), so instead of total 30 (correct) you will end up with a value of 55(incorrect).
    The difference here is that your delta which failed had a qty of 5 (incremental amount) for this doc, but now you are bringing the qty of 30 with a full load.
    This is a theortical scenario which can cause inconsistency to your data. If there is no case where an earlier existing record was being changed in the last delta (ie last delta had all new records) then you should be ok.

Maybe you are looking for

  • How can I insert a song into lots of different projects without it duplicating so many time?

    I have a website where I upload a daily one minute video, and I use the same song for the opening, and the same song for the closing. I have been trying to figure out why so much space is being used. One issue is that the songs I have been using for

  • BW authorizations testing

    Hello BW Experts, What testing strategies, plans can be done for BW authorizations before go-live. Any documentation or hints / links / pointers would be of a great help. Are there any populars checks that needs to carried out.   Many thanks in advan

  • Error in Creating sales order

    Hi guys while creating a Sales order i have encountered a problem.when i entered the following informations i got the following error Transaction code:VA01 order type : OR salesOrg   : JNOS Distbchannl: XC Division   : FD Salesoffice:JS00 Salesgroup

  • Development Tools: Which of them i really need?

    Hi, guys! I've just started to learn Java language & gonna develop midlets for most modern wireless devices. Please tell me what tools i really need to download. I've already downloaded Wireless Toolkit (with latest patch) & JRE. I guess i need some

  • Sony Bravia as Monitor

    I recently hooked up my laptop to our 32" Sony Bravia TV with an HDMI cable and used it as a second monitor with FCP. My HD footage looked great, and having the real estate for my timeline was fantastic. I'm in the market for a big monitor, and the B