* CUBE
---------
OLAP environment views data in the form of a hierarchical cube. A 'cube' is data set that incudes
both detailed and aggregated data 'rolled up' along its dimension hiearachy.
The bottom line is you want to get the data from the database that represents the logical cube.
How do you do this in ORACLE 9i? Is it possible to retrieve the cube data with SQL that people
are already familiar with? The answer is yes. ORACLE extends SQL with the 'ROLLUP' and 'CUBE'
clause which enable the retrieval of hierarchical cube data.
For example:
SELECT country_id, cust_state_province, cust_city, prod_category,
prod_subcategory, prod_name, calendar_month_number,
day_number_in_month, day_number_in_week,
GROUPING_ID(country_id, cust_state_province, cust_city,
prod_category, prod_subcategory, prod_name,
calendar_month_number, day_number_in_month,
day_number_in_week) gid,
SUM(amount_sold) s_sales,
COUNT(amount_sold) c_sales,
COUNT(*) c_star
FROM sales s, products p, customers c, times t
WHERE s.cust_id = c.cust_id AND s.prod_id = p.prod_id
AND s.time_id = t.time_id
GROUP BY
ROLLUP(country_id, (cust_state_province, cust_city)),
ROLLUP(prod_category, (prod_subcategory, prod_name)),
ROLLUP(calendar_month_number, (day_number_in_month,
day_number_in_week))
In reality, to speed up performance, you would certainly want to create Materialized view
based on these type of queries. In a sense, this type of materialized view is almost like
a 'CUBE'. Materialized a logicle cube, if you will.
* Dimension
------------------
In 9i, you can create the 'DIMENSION' object. This is in addition to the dimension 'tables'
that already exists in the database. What is DIMENSION for? Simply put, it helps query rewrite
perform more complex types of rewrite. Refer to Metalink 124791.1 for an example.
For example:
CREATE DIMENSION products_dim
LEVEL product IS (products.prod_id)
LEVEL subcategory IS (products.prod_subcategory)
LEVEL category IS (products.prod_category)
HIERARCHY prod_rollup (
product CHILD OF
subcategory CHILD OF
category
)
ATTRIBUTE product DETERMINES
(products.prod_name, products.prod_desc,
prod_weight_class, prod_unit_of_measure,
prod_pack_size,prod_status, prod_list_price, prod_min_price)
ATTRIBUTE subcategory DETERMINES
(prod_subcategory, prod_subcat_desc)
ATTRIBUTE category DETERMINES
(prod_category, prod_cat_desc);