GROUP BY CUBE
Hello,
is there any difference between those two querries ?
SELECT columnA, columnB, COUNT(*)
FROM table1
GROUP BY CUBE(columnA, columnB)
SELECT columnA, columnB, COUNT(*)
FROM table1
GROUP BY CUBE(columnB, columnA)
I know it matters when using ROLLUP, but does the order of the columns has any impact in the GROUP BY CUBE statement ?
Ikrischer wrote:
I never thought a query with a SET operator is sorted, I was surprised myself. First of all SET is a function, not an operator. Secondly, query with SET function is not sorted. SET function apples to nested table, not to a query. I can write something like where SET is used as select-list expression:
SQL> create or replace
2 type SalList
3 as table of number(7,2)
4 /
Type created.
SQL> select deptno,
2 cast(collect(sal) as SalList) SalList
3 from emp
4 group by deptno
5 /
DEPTNO SALLIST
10 SALLIST(2450, 5000, 1300)
20 SALLIST(800, 3000, 800, 3000, 2975)
30 SALLIST(1500, 1500, 1250, 1500, 1250, 1250)
SQL> select deptno,
2 set(cast(collect(sal) as SalList)) SalList
3 from emp
4 group by deptno
5 /
DEPTNO SALLIST
10 SALLIST(2450, 5000, 1300)
20 SALLIST(800, 3000, 2975)
30 SALLIST(1500, 1250)
SQL> SET eliminated duplicates, but do you see salary set sorted? Anyway, I think you are talking about:
SELECT *
FROM TABLE(SET(nested_table))
/And this again will eliminate dups but not necessarily by sorting:
SQL> select * from table(set(NumList(3,2,1,3,3,2,1,1,2)));
COLUMN_VALUE
3
2
1
SQL> I have no idea if exam 1Z0-047 states that or not. I assume you misinterpreted what it states.
SY.
Similar Messages
-
Difference between group by roll up and group by cube
Please let me know with an example for the difference between group by roll up and group by cube.
thanks,
Vinodhhttp://download.oracle.com/docs/cd/B19306_01/server.102/b14223/aggreg.htm#sthref1601
-
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.1Hello,
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 -
Summary Report with cube and rollup
hi guys,
i m working a oracle 9i, i need a summary report after query execution. im using rollup and cube but it is giving me unwanted rows as well. for ex below
Select
IRH_REFNO,IRH_TDATE,IRH_BDAMT,IRH_RLOCN, IRH_ILOCN,IRH_EXPECTED_DATE,IRH_ADD_USERID ,
count(*),
sum(irh_bdamt)
from IRH
where IRH_INTYPE='R'
and IRH_RLOCN='EDP'
group by cube(IRH_REFNO,IRH_TDATE,IRH_BDAMT,IRH_RLOCN, IRH_ILOCN,IRH_EXPECTED_DATE,IRH_ADD_USERID )
Order by IRH_TDATE asc
i want only two columns to be computed at the end of query. i.e sum of BDAMT and count of rows. i dont want any groupings. any alternate for this.
thanks n regards
fkhanPlease post a create table statement, a few insert statements and the expected output, so we can help you.
Regards,
Rob. -
How to get sum distinct in the cube. Is it possible.
Here is the scenario.
One report has many countries on it but only one amount.
For a particular day we have the following data in the fact.
TRANSACTION_DAY_NO
Country
Total Amount
19900101
US
34
19900101
IND
35
19900101
IND
36
19900101
AUS
37
19900101
UNKNOWN
38
19900101
UNKNOWN
39
19900101
UNKNOWN
40
19900101
UNKNOWN
41
19900101
UNKNOWN
42
19900101
UNKNOWN
43
19900101
US
43
19900101
IND
42
There are 2 dimensions on the cube.
Date, Country.
I am not sure how to build a cube on this data.
with t as (
select 19900101 transaction_Day_no, 'US' country_no, 34 total_amount from dual union all
select 19900101, 'IND', 35 from dual union all
select 19900101, 'IND', 36 from dual union all
select 19900101, 'AUS', 37 from dual union all
select 19900101, 'UNKNOWN', 38 from dual union all
select 19900101, 'UNKNOWN', 39 from dual union all
select 19900101, 'UNKNOWN', 40 from dual union all
select 19900101, 'UNKNOWN', 41 from dual union all
select 19900101, 'UNKNOWN', 42 from dual union all
select 19900101, 'UNKNOWN', 43 from dual union all
select 19900101, 'US', 43 from dual union all
select 19900101, 'IND', 42 from dual
select transaction_day_no, country_no, sum(distinct total_amount) from t
group by cube(transaction_Day_no, country_no);
I am using AWM. I have tried to build by selecting the following aggregate for the cube
max for the country_no and
sum for the tranaction_Day_no
But i am getting incorrect results.
If i select sum for both country_no and transaction_no then also i get incorrect results.
Please help me solve this issue.
thanksThanks for all your reply's.
The problem is that i have duplicates because
One report can have many customers.
One customer can have many countries.
One customer can have many reports.
If i include the report number in the above data and do a sum on both day and report_number and max for everything else then everything is find and i am getting correct results.
But if i take out the report dimension then i am stuffed.
Also the problem is that i can't have one big dimension for the report as the number of reports are in access of 300M
We have tried to solve this issue by having the fullowing.
Dummy Cube.
This has all the combination of all the dimension in the fact table with the report dimension as only one row(-1)
Report Dimension for each Quarter(34M rows each)
Quarter Cube is build.
Then add the values from all the Quarter Cube with the Dummy Cube.
Tried for 2 Quarter and its working fine results are correct as well.
Only problem is that its taking a long time to build the cube because of the report dimension.
I am trying to find a way to remove the report dimension but still use it. As we only use report dimension at level 'ALL'
But if we do aggregation at 'ALL' level the answers are wrong again.
Thanks for looking into this and taking time to reply.
Regards
Alvinder -
Inventory Management Extractors via DSO to Cube 0IC_C03
Dear experts,
to fulfill the requirements of DataWarehouse spirit using Entry-, Harmonization- and Reporting-Layer I want to use for Inventory Management a Data Flow from extractors 2LIS_03_BX, 2LIS_03_BF and 2LIS_03_UM via DSO/DSOs and later on to Cube 0IC_C03.
In this forum there are some opened threads about this issue, but none has been resolved! Many hints are about the "How to Inventory Management..." - some other say: "You can use DSO's!" - others say: "Don't use DSOs!". So: Where is the truth? Is there anybody who can provide a really praticable way to implement the above mentioned data flow?
I'm so excited about your suggestions and answers.
Thanks in advance and regards
Patrick
--> Data Flow has to be in BW 7.0Hi Patrick,
Yes indeed there is.
Using DSOs in inventory flow is absolutely possible. Here's what you need to know and do:
1 - Firstly don't be apprehensive about it. Knowledge is power! We know that inventory uses ABR delta update methodology and that is supported by DSOs so no doubt abt it.
2 - Secondly Inventory is special because of non-cumulative and several rule group at cube level for BX and BF.
3 - Now as you want to use a DSO and I am presuming that this will be used for staging purpose, use a write optimized DSO as the first layer. While mapping from DS to this DSO, keep one to one mapping from field to Info-objects.
4- Keep in mind that from Infosource to 0IC_C03 there would be multiple rule groups present in transformations.
These rule groups will have different KPIs mapped with routines. The purpose is that from ECC only 1 field for quantity (BWMNG) and one field for value (BWGEO) is coming but from Infosource to 0IC_C03 the same fields in different rule groups are mapped to different KPIs (Stock in transit, vendor consignment, valuated stock etc) based on stock category, stock type and BW transaction keys.
5- So create a write optimized DSO. map it one to one from datasource fields. create/copy transformations from this DSO to cube maintaining the same rule groups and same logic.
6- you can also use standard DSO and create rule groups and logic at DSO level and then do one to one from DSO to Cube.
Keep in mind that these rule groups and logic in them should be precisely the same as in standard flow.
This should work.
Debanshu -
SQLDeveloper can't generate an explain-plan when using "cube"
If I want to create an explain-plan from the following statement, I get no explain-plan:
SELECT 1
FROM dual
GROUP BY CUBE( 2, 2, 2, 2, 2, 2, 2, 2, 2 )If I now want to create an explain-plan again, I get the following message (and still no explain-plan):
http://i.imgur.com/mGO6Z.jpg
I tried this a few times and of course with a fresh db-session where i didn't run any statements before.
I get this with:
SQLDeveloper Version 3.0.04 Build MAIN-04.34 (i.e. production)
DB 9.2.0.1.0
Oracle Instant Client 11.1.0.6.0
In Toad this works btw.
(Of course it makes no sense to run it on this statement, we encountered this problem with a really big SQL-statement where "cube" was used in an inline-view. SQLDeveloper then wasn't able to generate an explain-plan for the whole-statement)
Regards
Markusthat is correct. I wanted to keep the login page redirect inside my class method so that I could do the check every time someone came to pages that require authentication. I wanted it in the LoadState method so I can do a check there, redirect
them to login page or just get a cookie and then pass that cookie to page to build the UI for the page
I can do what you are suggesting and have actually tried it but then I have to track which page to take the user to after they log in...
I have multiple clicks in the appbar and pages from where the user can come to these authentication-bound pages..
Suggestions?
Also, what am I doing wrong in my class method that it doesn't navigate to the login page in the LoadState method?
Thanks
mujno -
JDBC 8.1.6.0.1 Bug with grouping function
Hi,
I found a bug in the JDBC 8.1.6.0.1 driver, concerning the new grouping functionality of Oracle 8.1.6. Look at the following code fragment:
String cSelect = "SELECT DACO_VU_NAME AS DIM1, ' ' AS DIM2, TO_CHAR(DACO_VERKAUFSDATUM,'yyyymm') AS DIM_DATE, GROUPING(DACO_VU_NAME) AS DIM1GROUP, GROUPING(' ') AS DIM2GROUP, GROUPING(TO_CHAR(DACO_VERKAUFSDATUM,'yyyymm')) AS DIM_DATEGROUP, sum(DACO_BRUTTOBETRAG_TX) AS VALUE FROM DATENCONTAINER GROUP BY CUBE (DACO_VU_NAME, '-', TO_CHAR(DACO_VERKAUFSDATUM,'yyyymm') ) ORDER BY 1,2,3";
try {
System.out.println("SELECT: " + cSelect);
Statement stmt = conn.createStatement();
ResultSet rset = stmt.executeQuery(cSelect);
while (rset.next()) {
String cTest1 = rset.getString("DIM1");
String cTest2 = rset.getString("DIM2");
String cTest3 = rset.getString("DIM_DATE");
String cChar1 = rset.getString("DIM1GROUP");
String cChar2 = rset.getString("DIM2GROUP");
String cChar3 = rset.getString("DIM_DATEGROUP");
System.out.println(cTest1 + "\t" + cTest2 + "\t" + cTest3 + "\t" + cChar1 + "\t" + cChar2 + "\t" + cChar3);
}When I compile this with the mentioned JDBC version and run it with java 1.2.2 (JDeveloper 3.1), i get the following output:
Ahrend GmbH & Co. KG 200003 0 0 0
Ahrend GmbH & Co. KG 200003 1 0 0
Ahrend GmbH & Co. KG 200004 0 0 0
Ahrend GmbH & Co. KG 200004 1 0 0
Ahrend GmbH & Co. KG null 0 0 1
Ahrend GmbH & Co. KG null 1 0 1
null 200003 0 1 0
null 200003 1 1 0
null 200004 0 1 0
null 200004 1 1 0
null null 0 1 1
null null 1 1 1As you can see, the grouping columns are mixed up. In this example, everywhere a normal row shows a "null" value, a corresponding grouping row should show a "1", but as you can see, for the last 6 rows, the ones are not in the first, but in the second grouping row.
When I compile the example with the Oracle 8.1.5 JDBC driver, I get the following, correct, output:
Ahrend GmbH & Co. KG 200003 0 0 0
Ahrend GmbH & Co. KG 200004 0 0 0
Ahrend GmbH & Co. KG null 0 0 1
Ahrend GmbH & Co. KG 200003 0 1 0
Ahrend GmbH & Co. KG 200004 0 1 0
Ahrend GmbH & Co. KG null 0 1 1
null 200003 1 0 0
null 200004 1 0 0
null null 1 0 1
null 200003 1 1 0
null 200004 1 1 0
null null 1 1 1The special thing about this example is, that I use a constant row for grouping (row 2). If you use a normal database row, everything works fine with 8.1.6.0.1, but nevertheless, this should be a bug.
Any comments on this are highly appreciated, since I need the JDK 1.2 for the application and I didn't find a working Oracle 1.2 JDBC version.
Thanks,
Thorsten.Patches can be obtained from an Oracle Support Services technical analyst.
null -
Hello!
I have just started to develope some apps for J2ME. Before I have explored Java3D so perhaps I tries to merge these two technics and there for run into this problem.
My plan for my first bigger app would consist of 4 classes.
CubeGame - the midlet
CubeCanvas - the canvas to display and render 3D objects.
Cube - a class that holds everything for a 3D cube-object.
RefreshTask - a timer class that i hope will be replaced by letting CubeCanvas implemets Runnable instead.
I also use a image for the texture for the cube, that one can be found at:
http://developers.sun.com/techtopics/mobility/apis/articles/3dgraphics/texture.png
The problem is that the cube never get's displayed when I start this app. I just see a black screen with my time counter. Perhasps it is there somewhere but is out of sight I do not know??
So if any one could tell me whats wrong and how to get the cube in the display please tell me!
Below is the source code.
Best regards
Fredrik Andersson
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import java.lang.*;
import java.io.*;
import java.util.*;
import javax.microedition.m3g.*;
public class CubeGame extends MIDlet implements CommandListener
static CubeGame instance;
CubeCanvas cubeCanvas = new CubeCanvas();
public CubeGame()
this.instance = this;
public void startApp()
Display.getDisplay(this).setCurrent(cubeCanvas);
Command exitCommand = new Command("Exit", Command.EXIT, 0);
cubeCanvas.addCommand(exitCommand);
cubeCanvas.setCommandListener(this);
public void pauseApp()
public void destroyApp(boolean unconditional)
public static void quitApp()
instance.destroyApp(true);
instance.notifyDestroyed();
instance = null;
public void commandAction(Command c, Displayable s)
if (c.getCommandType() == Command.EXIT)
notifyDestroyed();
import javax.microedition.lcdui.*;
import javax.microedition.m3g.*;
import java.util.*;
import javax.microedition.midlet.*;
public class CubeCanvas extends Canvas
private Graphics3D graphics3D;
private Camera camera = new Camera();
private Light light = new Light();
private Transform transform = new Transform();
private Background background = new Background();
private World world = new World();
private byte time = 100;
private Group group = new Group();
private Timer timer = new Timer();
private TimerTask timerTask = null;
private Cube cube = new Cube();
public CubeCanvas()
init();
public void init()
graphics3D = Graphics3D.getInstance();
background.setColor(0x33ccff);
world.addChild(group);
group.setOrientation(15.0f, 1.0f, 0.0f, 0.0f);
group.addChild(cube);
world.addChild(camera);
world.setActiveCamera(camera);
camera.setParallel((1<<3)*1.5f, 1.0f, -(1<<3), (1<<3));
camera.setPerspective( 60.0f, // field of view
(float)getWidth()/ (float)getHeight(), // aspectRatio
1.0f, // near clipping plane
1000.0f ); // far clipping plane
// create a light
light.setColor(0xffffff); // white light
light.setIntensity(1.25f); // overbright
world.addChild(light);
public void rotateCube(short cubeId, short dircetion)
public void connectCubes(short cubeId, short dircetion)
public void paint(Graphics g)
if(this == null || world == null)
return;
if(timerTask != null)
timerTask.cancel();
timerTask=null;
graphics3D.bindTarget(g);
graphics3D.clear(background);
Transform transform = new Transform();
transform.postTranslate(0.0f, 0.0f, 10.0f);
graphics3D.setCamera(camera, transform);
// set up a "headlight": a directional light shining
// from the direction of the camera
graphics3D.resetLights();
graphics3D.addLight(light, transform);
try
graphics3D.render(world);
finally
graphics3D.releaseTarget();
g.setColor(0xFFFFFFFF);
g.drawString(time + " sec", 10, 30, Graphics.LEFT | Graphics.TOP);
timerTask = new RefreshTask(this);
timer.schedule(timerTask, 1000);
time--;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import java.lang.*;
import java.io.*;
import java.util.*;
import javax.microedition.m3g.*;
public class Cube extends Group
private short size;
private Image[] images;
private VertexBuffer vertexBuffer; // positions, normals, colors, texcoords
private IndexBuffer indexBuffer; // indices to vertexBuffer, formingtriangle strips
private Appearance appearance; // material, texture, compositing, ...
private Material material = new Material();
private Mesh mesh;
private Image iImage;
short[] vert = {
1, 1, 1, -1, 1, 1, 1,-1, 1, -1,-1, 1, // front
-1, 1,-1, 1, 1,-1, -1,-1,-1, 1,-1,-1, // back
-1, 1, 1, -1, 1,-1, -1,-1, 1, -1,-1,-1, // left
1, 1,-1, 1, 1, 1, 1,-1,-1, 1,-1, 1, // right
1, 1,-1, -1, 1,-1, 1, 1, 1, -1, 1, 1, // top
1,-1, 1, -1,-1, 1, 1,-1,-1, -1,-1,-1 }; // bottom
byte[] norm = {
0, 0, 127, 0, 0, 127, 0, 0, 127, 0, 0, 127,
0, 0,-127, 0, 0,-127, 0, 0,-127, 0, 0,-127,
-127, 0, 0, -127, 0, 0, -127, 0, 0, -127, 0, 0,
127, 0, 0, 127, 0, 0, 127, 0, 0, 127, 0, 0,
0, 127, 0, 0, 127, 0, 0, 127, 0, 0, 127, 0,
0,-127, 0, 0,-127, 0, 0,-127, 0, 0,-127, 0 };
short[] tex = {
1, 0, 0, 0, 1, 1, 0, 1,
1, 0, 0, 0, 1, 1, 0, 1,
1, 0, 0, 0, 1, 1, 0, 1,
1, 0, 0, 0, 1, 1, 0, 1,
1, 0, 0, 0, 1, 1, 0, 1,
1, 0, 0, 0, 1, 1, 0, 1 };
int[] stripLen = { 4, 4, 4, 4, 4, 4 };
//public Cube(short s, Image[] i)
public Cube()
try
//size = s;
//images = i;
VertexArray vertArray = new VertexArray(vert.length / 3, 3, 2);
vertArray.set(0, vert.length/3, vert);
VertexArray normArray = new VertexArray(norm.length / 3, 3, 1);
normArray.set(0, norm.length/3, norm);
VertexArray texArray = new VertexArray(tex.length / 2, 2, 2);
texArray.set(0, tex.length/2, tex);
VertexBuffer vertexBuffer = new VertexBuffer();
vertexBuffer.setPositions(vertArray, 1.0f, null); // unit scale, zerobias
vertexBuffer.setNormals(normArray);
vertexBuffer.setTexCoords(0, texArray, 1.0f, null); // unit scale, zerobias
indexBuffer = new TriangleStripArray( 0, stripLen );
iImage = Image.createImage( "/images/texture.png" );
Image2D image2D = new Image2D( Image2D.RGB, iImage );
Texture2D texture = new Texture2D( image2D );
texture.setFiltering(Texture2D.FILTER_NEAREST, Texture2D.FILTER_NEAREST);
texture.setWrapping(Texture2D.WRAP_CLAMP, Texture2D.WRAP_CLAMP);
texture.setBlending(Texture2D.FUNC_MODULATE);
appearance = new Appearance();
appearance.setTexture(0, texture);
appearance.setMaterial(material);
material.setColor(Material.DIFFUSE, 0xFFFFFFFF); // white
material.setColor(Material.SPECULAR, 0xFFFFFFFF); // white
material.setShininess(100.0f);
mesh = new Mesh(vertexBuffer, indexBuffer, appearance);
catch(Exception e)
e.printStackTrace();
public short getSize()
return size;
public Image[] getImages()
return images;
import java.util.*;
public class RefreshTask extends TimerTask
CubeCanvas cubeCanvas;
public RefreshTask(CubeCanvas cc)
cubeCanvas = cc;
public void run()
cubeCanvas.repaint();
}Hello Mates!
(Greetings from a cold Sweden -20 deg. cel. this morning very unusually so late in the winter)
At last I solved it. Now I think I got hold of this.
I use immediate mode. I do not know if this is a good thing if we talk performance.
My intention was to be able to progamatically create different objects and add them to my world. I'm not so found of creating things in a 3D-program. I rather create them my self. Now I think I know how!
Perhaps you can advise me not to do this if you see that this would leak memory or something else. Perhaps it is better to use m3g-files, I do not know. But I do not like it.
Now my app contains these 4 classes:
TestMIDlet - just the start class for everything
TestCanvas3D - this is the interesting class that contains everything for the rendering and the world to attach objects into.
Cube - All data for a 3D-cube
Pyramid - All data for a Pyramid, I guess, I have copied you Mitch
This app displays these two objects. My intention is now to create a 3D-world progamatically. So please comment this if you in any way think this is stupid.
/Fredrik
The code is below:
Code:
import javax.microedition.lcdui.*;
import javax.microedition.m3g.*;
import java.util.*;
import javax.microedition.midlet.*;
public class TestMIDlet extends MIDlet implements CommandListener
private Display display = null;
private TestCanvas3D testCanvas3D = new TestCanvas3D();
private Command exitCommand = new Command("Exit", Command.ITEM, 1);
public TestMIDlet()
display = Display.getDisplay(this);
testCanvas3D.setCommandListener(this);
testCanvas3D.addCommand(exitCommand);
public void startApp() throws MIDletStateChangeException
try
testCanvas3D.setTitle("TestMIDlet");
display.setCurrent(testCanvas3D);
catch(Exception e)
e.printStackTrace();
public void pauseApp()
public void destroyApp(boolean unconditional) throws MIDletStateChangeException
public void commandAction(Command command, Displayable displayable)
if (command == exitCommand)
try
destroyApp(false);
notifyDestroyed();
catch(Exception e)
e.printStackTrace();
import javax.microedition.lcdui.*;
import javax.microedition.m3g.*;
import java.util.*;
import javax.microedition.midlet.*;
public class TestCanvas3D extends Canvas
private Graphics3D graphics3D = Graphics3D.getInstance();
private Camera camera = new Camera();
private World world = new World();
private Background background = new Background();
private Light light = new Light();
private Pyramid pyramid1 = new Pyramid(0xFFFFFF00);
private Cube cube = new Cube();
private Transform cameraTransform = new Transform();
private Transform worldTransform = new Transform();
private Transform lightTransform = new Transform();
public TestCanvas3D()
Transform transform1 = new Transform();
transform1.postTranslate(-0.5f, 0.0f, -8.0f);
pyramid1.setTransform(transform1);
Transform transform2 = new Transform();
transform2.postTranslate(0.5f, 0.0f, -8.0f);
cube.setTransform(transform2);
world.addChild(pyramid1);
world.addChild(cube);
world.setActiveCamera(camera);
worldTransform.postTranslate(0.0f, 0.0f, 0.0f);
lightTransform.postTranslate(0.0f, 0.0f, 10.0f);
graphics3D.resetLights();
graphics3D.addLight(light, lightTransform);
float aspect = (float) getWidth() / (float) getHeight();
camera.setPerspective(60.0f, aspect, 1.0f, 1000.0f);
cameraTransform.postTranslate(0.0f, 0.0f, 0.0f);
graphics3D.setCamera(camera, cameraTransform);
protected void paint(Graphics g)
graphics3D.bindTarget(g);
try
graphics3D.clear(null);
graphics3D.render(world, worldTransform);
finally
graphics3D.releaseTarget();
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import java.lang.*;
import java.io.*;
import java.util.*;
import javax.microedition.m3g.*;
public class Cube extends Group
private short size;
private Image[] images;
private VertexBuffer vertexBuffer; // positions, normals, colors, texcoords
private IndexBuffer indexBuffer; // indices to vertexBuffer, formingtriangle strips
private Appearance appearance; // material, texture, compositing, ...
private Material material = new Material();
private Mesh mesh;
private Image iImage;
short[] vert = {
1, 1, 1, -1, 1, 1, 1,-1, 1, -1,-1, 1, // front
-1, 1,-1, 1, 1,-1, -1,-1,-1, 1,-1,-1, // back
-1, 1, 1, -1, 1,-1, -1,-1, 1, -1,-1,-1, // left
1, 1,-1, 1, 1, 1, 1,-1,-1, 1,-1, 1, // right
1, 1,-1, -1, 1,-1, 1, 1, 1, -1, 1, 1, // top
1,-1, 1, -1,-1, 1, 1,-1,-1, -1,-1,-1 }; // bottom
byte[] norm = {
0, 0, 127, 0, 0, 127, 0, 0, 127, 0, 0, 127,
0, 0,-127, 0, 0,-127, 0, 0,-127, 0, 0,-127,
-127, 0, 0, -127, 0, 0, -127, 0, 0, -127, 0, 0,
127, 0, 0, 127, 0, 0, 127, 0, 0, 127, 0, 0,
0, 127, 0, 0, 127, 0, 0, 127, 0, 0, 127, 0,
0,-127, 0, 0,-127, 0, 0,-127, 0, 0,-127, 0 };
short[] tex = {
1, 0, 0, 0, 1, 1, 0, 1,
1, 0, 0, 0, 1, 1, 0, 1,
1, 0, 0, 0, 1, 1, 0, 1,
1, 0, 0, 0, 1, 1, 0, 1,
1, 0, 0, 0, 1, 1, 0, 1,
1, 0, 0, 0, 1, 1, 0, 1 };
int[] stripLen = { 4, 4, 4, 4, 4, 4 };
//public Cube(short s, Image[] i)
public Cube()
try
//size = s;
//images = i;
VertexArray vertArray = new VertexArray(vert.length / 3, 3, 2);
vertArray.set(0, vert.length/3, vert);
VertexArray normArray = new VertexArray(norm.length / 3, 3, 1);
normArray.set(0, norm.length/3, norm);
VertexArray texArray = new VertexArray(tex.length / 2, 2, 2);
texArray.set(0, tex.length/2, tex);
VertexBuffer vertexBuffer = new VertexBuffer();
vertexBuffer.setPositions(vertArray, 1.0f, null); // unit scale, zerobias
vertexBuffer.setNormals(normArray);
vertexBuffer.setTexCoords(0, texArray, 1.0f, null); // unit scale, zerobias
indexBuffer = new TriangleStripArray( 0, stripLen );
iImage = Image.createImage( "/images/texture.png" );
Image2D image2D = new Image2D( Image2D.RGB, iImage );
Texture2D texture = new Texture2D( image2D );
texture.setFiltering(Texture2D.FILTER_NEAREST, Texture2D.FILTER_NEAREST);
texture.setWrapping(Texture2D.WRAP_CLAMP, Texture2D.WRAP_CLAMP);
texture.setBlending(Texture2D.FUNC_MODULATE);
appearance = new Appearance();
appearance.setTexture(0, texture);
appearance.setMaterial(material);
material.setColor(Material.DIFFUSE, 0xFFFFFFFF); // white
material.setColor(Material.SPECULAR, 0xFFFFFFFF); // white
material.setShininess(100.0f);
mesh = new Mesh(vertexBuffer, indexBuffer, appearance);
addChild(mesh);
catch(Exception e)
e.printStackTrace();
public short getSize()
return size;
public Image[] getImages()
return images;
import javax.microedition.lcdui.*;
import javax.microedition.m3g.*;
import java.util.*;
import javax.microedition.midlet.*;
public class Pyramid extends Group
Appearance appearance = new Appearance();
IndexBuffer triangles = null;
VertexBuffer vertices = new VertexBuffer();
Mesh mesh;
public Pyramid(int color)
// Appearance and materials;
Material material = new Material();
appearance.setMaterial(material);
material.setColor(Material.DIFFUSE, color ); // yellow
// coordinates - These are the vertex positions
short[] coordinates = { -1, -2, -1, 1, -2, -1, 0, 2, -1 };
VertexArray vaCoordinates = new VertexArray( (coordinates.length/3), 3, 2);
vaCoordinates.set(0, (coordinates.length/3), coordinates);
vertices.setPositions(vaCoordinates, 1, null);
// Normals - first two point back at the light, the last normal points down just as an experiment
byte[] normals = { 0, 0, 127, 0, 0, 127, 0, -128, 0 };
VertexArray vaNormals = new VertexArray( (normals.length/3), 3, 1);
vaNormals.set(0, (normals.length/3), normals);
vertices.setNormals(vaNormals);
int[] coordIndex = {3};
triangles = new TriangleStripArray(0, coordIndex);
VertexBuffer vertexBuffer = new VertexBuffer();
vertexBuffer.setPositions(vaCoordinates, 1.0f, null); // unit scale, zerobias
vertexBuffer.setNormals(vaNormals);
mesh = new Mesh(vertexBuffer, triangles, appearance);
addChild(mesh);
Remeber that the cube uses the png mentioned above -
Aggreate functions(cube,rollup)
Hi,
Is it possible to use aggrgate funtions (cube, rollup) with Oracle Express ?
Thanks
MarcoI don't find any documentation about aggregate functions like cube, rollup, grouping set in XE librairy. But it works !
select MANAGER_ID, DEPARTMENT_ID, count(EMPLOYEE_ID)
from HR.EMPLOYEES
group by rollup MANAGER_ID, DEPARTMENT_ID);
select MANAGER_ID, DEPARTMENT_ID, count(EMPLOYEE_ID)
from HR.EMPLOYEES
group by cube (MANAGER_ID, DEPARTMENT_ID);
select MANAGER_ID, DEPARTMENT_ID, count(EMPLOYEE_ID)
from HR.EMPLOYEES
group by
grouping sets (MANAGER_ID, DEPARTMENT_ID);
It's great ! -
<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 -
In BW 3.5 ->RSA1 ->Administraction ->InfoPackages, I click on the InfoPackage Group Sales Cube, I have 5 InfoPackages.
Sale Cube 2001
Sale Cube 2002
Sale Cube 2003
Sale Cube 2004
Sale Cube 2005
What does it mean is if I run this InfoPackage Group, all the 5 InfoPackages will be triggered right?
I would like to convert this InfoPackage Group into Process Chain, So I:
1) Double-click on the InfoPackage Group Sales Cube
2) The Scheduler (Maintain InfoPackageGroup) open up. I click on the Process Chain Maint button
3) Enter the Process Chain Name as SaleCube.
4) In the Process Chain screen, I see the Process Chain SaleCube created with the 5 InfoPackages.
5) However, all this 5 InfoPackages not appear/link at the same level or right sequence. It is:
Start Process
Sale Cube 2001
Sale Cube 2002
Sale Cube 2003
Sale Cube 2004
Sale Cube 2005
So Sale Cube 2002 is depend on Sale Cube 2001 etc, Why? I thought all the 5 InfoPackages should appear under the Start Process right?HI,
Have to include all the infopackages from your IP group individually in the process chain. Include the infopackages in the same order as in the IP group.
set delay time (as in IP group) for some of the infopackage execution using "wait" time option in the process chain.
set the option for " when to execute which infopackage" - whether on success of the earlier IP or failure or always execute in the process chain.
Re: Process chains
Re: Regarding Converting Inofpackage Groups to Process Chains
Process Chain?
Thanks/Tarak
Edited by: Tarak on Jan 12, 2009 7:08 AM
Edited by: Tarak on Jan 12, 2009 7:18 AM -
Hi All,
I am working on a data warehousing project. I have 7 dimensions and one fact table. I am planning to create a materialized view with aggregate values based on the dimension keys. In my Mview query I am trying to use parallel option and group by cube clause. I am using 9 keys in the cube clause. When I did explain plan the cost of the query is 8537. But the query takes for ever to run. I let it run for more than 3 hrs still I did not get the output.
Can anyone please tell me if it is advisable to use these many keys in cube. I read in the documentation that cube is more expensive. So, this time I tried to use grouping sets clause with 2 key combinations. The cost was around 50k and I got the result in 5 mins. Then, I changed the grouping sets clause to have 4 keys the cost bumped up to 800k. The query ran for 25 min and failed throwing an error message "Unable to extend temp segment"
DB settings are 128gb memory, 80gb of temp table space. Oracle version is 11g.
Any help/inputs are greatly appreciated.
Thanks
HariWhat I recommend is computing only the combinations you need. For example with 9 entries in the group by clause Oracle has to compute 2^9 or 512 combinations. This obviously can take a significant amount of time. Once you figure out the combinations you need you may be able to achieve the required results with partial cubes, or combinations of grouping sets and rollup statements.
See the following link for a lot of good examples: [SQL for Aggregation in Data Warehouses|http://download.oracle.com/docs/cd/B19306_01/server.102/b14223/aggreg.htm#i1007428]
HTH! -
The following query throws up 'Not a group by Expression' Error:
select decode(visited_last_date,sysdate,'Present','null') ,forum_name
from disc_forum f, disc_emp_pref p
where f.forum_category='TSP'
and f.forum_short_name=p.forum_short_name group by f.forum_short_name
How can i get this working? I need to retain the group-by clause.Thanx Detlev,
The query works with the group fn. But the actual query that i'm working on is:
select DECODE(visited_last_date,sysdate,'<img src="/images/on.gif">','null') img, ''| |f.forum_name| |'' forum_name, count(message_id) Posts, to_char(max(m.posted_date),'DD-MON-YYYY') last_updated from disc_message m, disc_thread t,disc_forum f,disc_emp_pref p where f.forum_category=nvl(:category,f.forum_category) and f.forum_short_name=t.forum_short_name(+) and t.thread_id=m.thread_id(+) group by cube(f.forum_name,f.forum_short_name,f.forum_description,p.visited_last_date)
I'm using this query to build a report in Oracle Portal. This query is working only that i'm getting duplicate rows. If i don't include the visited_last_date in the group_by clause then it flags a 'Not a group-by expr' error. How do i avoid that -
GROUP BY ROLLUP with Grouped Category Subtotals
Hi,
I need the categories to have group totals like the example below. Notice that California has it's own category subtotals then a grand total.
I could do this with unions, a row type column, and sorting, but that would mean reading the entire table for each total snd subtotal.
Any suggestions?
Thank You in Advance for Your Help,
Lou
My Data
STATE CITY CATEGORY NBR
California Los Angeles AA 1
California Los Angeles BB 2
California Los Angeles CC 3
California San Diego AA 4
California San Diego BB 5
California San Diego CC 6
California San Francisco AA 7
California San Francisco BB 8
California San Francisco CC 9
Desired Result
STATE CITY CATEGORY NBR
California Los Angeles AA 1
California Los Angeles BB 2
California Los Angeles CC 3
California Los Angeles 6
California San Diego AA 4
California San Diego BB 5
California San Diego CC 6
California San Diego 16
California San Francisco AA 7
California San Francisco BB 8
California San Francisco CC 9
California San Francisco 24
California AA 12
California BB 15
California CC 18
Grand Total 45My bad, that would be a cube then
SQL> with t as (select 'California' state, 'Los Angeles' city, 'AA' categ, 1 nbr from dual
2 union all select 'California' state, 'Los Angeles' city, 'BB' categ, 2 nbr from dual
3 union all select 'California' state, 'Los Angeles' city, 'CC' categ, 3 nbr from dual
4 union all select 'California' state, 'San Diego' city, 'AA' categ, 4 nbr from dual
5 union all select 'California' state, 'San Diego' city, 'BB' categ, 5 nbr from dual
6 union all select 'California' state, 'San Diego' city, 'CC' categ, 6 nbr from dual
7 union all select 'California' state, 'San Francisco' city, 'AA' categ, 7 nbr from dual
8 union all select 'California' state, 'San Francisco' city, 'BB' categ, 8 nbr from dual
9 union all select 'California' state, 'San Francisco' city, 'CC' categ, 9 nbr from dual)
10 select state,
11 city,
12 categ,
13 sum(nbr) total
14 from t
15 group by cube(state, city, categ)
16 having (grouping(city) = 1 and grouping(state) = 0)
17 or (grouping(categ) = 0 and grouping(city) = 0 and grouping(state) = 0)
18 order by state, city, categ
19 /
STATE CITY CA TOTAL
California Los Angeles AA 1
California Los Angeles BB 2
California Los Angeles CC 3
California San Diego AA 4
California San Diego BB 5
California San Diego CC 6
California San Francisco AA 7
California San Francisco BB 8
California San Francisco CC 9
California AA 12
California BB 15
STATE CITY CA TOTAL
California CC 18
California 45
13 linhas selecionadas.
SQL> You can play around with the having clause and groupings and select the rows as needed.
Regards,
Francisco.
Edited by: fsitja on Mar 24, 2009 6:11 PM
Edited by: fsitja on Mar 24, 2009 6:14 PM
Maybe you are looking for
-
Safari on my macbook pro keeps closing seconds after i open it
Everytime I open safari on my macbook pro it closes in about 30 seconds and asks me to send a report to apple. I know that my wireless internet is working - I can use facetime or the app store just fine. Any suggestions?
-
WebLogic Server 9.2.2 & running WLS 9.1 generated WLST config.py
Hello everybody, I am running a WLS 9.1 WLST ConfigToScript config.py in a blank new WLS 9.2 installation to recreate a WLS Server domain. The original script generated reflects the Administration Server residing on one machine while the Application
-
Have lion thumbdrive already, want to install lion server
I purchased the Lion thumbdrive -- installed it on my Mac Pro; now I want to upgrade my MacMini Server from 10.8 to Lion; I put the thumbdrive in the miniserver and I get the following message: "Waiting for App Store to download Mac OS X Server Add O
-
Casting, need a bit help here.
Here's my code: @Test public void testInsertElementAt() { Movie m1 = new Movie("The Matrix Revolutions", 4); PriorityList list = new ArrayPriorityList(); list.insertElementAt(0, m1); assertEquals("The Matr
-
When I try to import the transport request it throws error " Acess denied on qcxsaqai\sapmnt\trans\tmp\SLOG0832.PCX.LOC is already in use pcxsaprd. Intially it was working fine , just few days before I have included training system in between Dev,QA,