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

Similar Messages

  • 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..

  • 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

  • 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

  • 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

  • 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.

  • 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

  • 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.

  • How to underline a row in report...

    Hi,
    I have a report with 3 text fields.
    I need to underline every row of the report and have a problem with that.
    Why?... well I will try to explain the problem.
    for example:
    I draw a line in the bottom of the repeating frame where the field are.
    The field1 expands through 2 rows, field2 through 3 rows and field 4 through 4 rows.
    ...and the problem is: when I run the report he draws the line under the 1st row of first record because the first field is long only one row. That means that he draws the line over the values of the the field2 and field3 and they are not underlined they are crosslined ( hope this is a rigth word for that ).
    He draws the line under the first field no matter how long are the other field.
    If the first field is longer than the other two that he draws it OK, but if not that he crossline the other values.
    Hope I explained my problem in understandable way...
    So if somebody could help me or give me a hint...
    regards,
    Mzz

    One method would be to use ROLLUP in your SQL
    http://www.oracle-base.com/articles/misc/rollup-cube-grouping-functions-and-grouping-sets.php

  • 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

  • How to generate a row in report to compute total?

    Hi:
    I need help to generate a report. In an accounting report, I need to make sum for each client regarding outstanding balance. The format of report is following:
    invoice#, invoice date, invoice amount, paid amount paid date, write off, outstanding balance
    Client Name: Baker Express / Debtor Name: Kurt Weiss inc.
    137308001, 04/18/2012, 438.07, 537.07, 06/05/2012, , (99)
    137308002, 04/18/2012, 100, 90, 06/05/2012, 10,
    client Total: total payment:627.07, total outstanding balance: (99)
    another client and debtor pair
    My question is how to generate total payment and total outstanding balancefor every pair of client and debtor. And there are multiple pairs. I tried to use group by, but how can I display every invoice tuple as well in the report?
    Any help would be appreciated.
    Sam

    One method would be to use ROLLUP in your SQL
    http://www.oracle-base.com/articles/misc/rollup-cube-grouping-functions-and-grouping-sets.php

  • Dimension declaration. Why do we need it?

    Hey, Oracle data warehouse gurus.
    It should be an easy question for you.
    Why do we need to declare dimension on the top of the dimension table (CREATE DIMENTION dimension_name ...)?
    It seems to me that many functions such as rollup, cube and the like do not need this dimension metadata.
    I am using Crystal Holos OLAP server to do data mining and reporting and again this tool (at least version 7.5) does not use dimension metadata. I suppose that some OLAP servers do.
    Thanks in advance for your answer.
    Best Regards
    Vadim

    Hello  Rajsan Madhavarajan  
    Query as a Web Service (QaaWS) is a SAP Business Objects (BOBJ)  client-side tool that allows users to create and publish Web Services that can be made available over the Web.  Once these web services are created and published,  they can be consumed like any other standard Web Service in software applications including Xcelsius and Crystal Reports.   But first we have to understand what exactly is a Web Service.
    Web Service
    A Web Service is a software system that supports  interoperable interaction over a network from one computer or machine to another but is more commonly defined as a client and a server communicating data over the Web using the HTTP Protocol. Using Web Services along with Business Objects allows a live connection of data to be used in applications such as Xcelsius and Crystal Reports through a semantic layer called a Universe.
    Query as a Web Service (QaaWS)
    The two main components in QaaWS are the Client Tool and the Server.  The QaaWS Client Tool gives the end user an easy to use wizard that allows them to create Universe queries and publish them as Web Services.  Once the QaaWS is published, any user can securely access the data that the Web Service contains as long as they have access to that server. Have a look on  image below that shows the information flow to and from the server via the client.
    Advantages to QaaWS:
    Very easy to use and intuitive interface Familiar look and feel for people who have used Web Intelligence
    Leverages existing Business Objects Universes Shares metadata with Web Intelligence, Desktop Intelligence and Crystal Reports
    Maintains Business Objects Enterprise Security
    Allows live data feeds to be incorporated into Xcelsius Dashboards and Crystal Reports

Maybe you are looking for

  • Data conversion from I32 to U8

    Hello, I have Data in I-32 ( 1D-Array 32 Bit)  and I want to convert it into U8 ( 1D-Array 8 Byte) how I can doing that with Labview?  BR

  • Cursor within cursor insert problem.

    Hello, Am trying to pass a parameter from one cursor to another and making an insert in the 2nd cursor but its not inserting. declare v_txt_1 varchar2(10); v_txt_2 varchar2(10); cursor C1 is select txt1,txt2 from test1where country='INI'; cursor C2(p

  • Loading from ODS to Cube

    I have a process chain for GL. Data was getting loaded first to ODS and then to CUBE. Now i there is no update to cube is scheduled. I removed  'Further Update'  process from process chain. During loading  I am getting a warning message as follow: Th

  • Moving from LR4 to LR5

    What is the best way to import my LR4 catalog into LR5?

  • How long does everyone elses battery last?

    I took my powerbook to my local apple store because I thought something might be wrong with it. They told me nothing was wrong with it. I know apple says it will run about 5 hours. The "genius" told me that is only true if you are not using ANY progr