Oracle Cube | Cube - oracle tutorial - sql tutorial
What is Oracle CUBE ?
- In addition to the subtotals generated by the ROLLUP extension, the CUBE extension will generate subtotals for all combinations of the dimensions specified.
oracle tutorial , sql tutorial , sql , pl sql tutorial , oracle , pl sql , plsql
Syntax:
SELECT Column_1,
Column_2,
SUM(some_column) AS some_column
FROM table_name
GROUP BY CUBE (Column_1,Column_2,..)
ORDER BY column_1, Column_2;
click below button to copy the code. By - oracle tutorial - team
Example:
SELECT id,
name,
SUM(salary) AS salary
FROM wikitechy_employee
GROUP BY CUBE (id, city)
ORDER BY id, name;
click below button to copy the code. By - oracle tutorial - team
Sample Database:
- For better understanding of cube concept we are using a Wikitechy_employee table.

Code Explanation:

- The select list contains the dimension columns and aggregate function expressions selected from wikitechy_employee table.
- The CUBE operator is specified in the GROUP BY clause of a SELECT statement.
- The GROUP BY specifies the dimension columns and the keywords WITH CUBE.

Oracle cubes-data-warehousing-data-mart
Cube Example Output:

- This row report the subtotal for the City dimension. It have null in the ID dimension to show that the aggregate data came from row having any value for the ID dimension.
- This row depicts the total value of each city.