Create Pivot Tables
in Oracle

Oracle Pivot Table functionality helps rearrange rows and columns of data to a simplified table the way you want to understand data relations and dependencies. This page provides a brief overview of the pivot function of dbForge Studio for Oracle and describes the process of the pivot table creation.

Become a data management guru with dbForge Studio for Oracle, now featuring Oracle Pivot Table. The Oracle Pivot Table function converts large amounts of data into compact and informative summaries - pivot tables. In an intuitive and easy-to-use visual Query Builder, pivoting a table without crosstab becomes a quick and simple task: drag-and-drop tables, select columns, create JOINS, and set up filtering, grouping or sorting relations between tables in the tabbed editor, as well as sum, store, and generate data into a report. With a few clicks, you can aggregate the data and pivot rows into columns.

  • Simplify data representation
  • Summarize data in an easy and flexible way
  • Customize totals for column or row values
  • Highlight the most important information in a report
  • Use a bunch of metrics to build pivot tables effectively and efficiently
  • Improve data analysis manipulation

Pivot Operator in Oracle

Oracle Database delivers PIVOT functionality designed to help summarize and analyze volumes of data in your database. The feature enables Oracle database users to transpose rows to columns and present any type of query in the crosstab format using a pivot operator. Before Oracle 11 g, you could obtain similar results by means of the DECODE function or CASE expressions, but the technique was quite cumbersome and time-consuming. The pivot feature saves you extra effort writing complex SQL and allows reorganizing your data and viewing it in a concise format. Let's review the basic functions in Oracle related to the PIVOT operator.

Multiple Columns

Pivot Multiple Columns

Using the Oracle SQL Pivot statement, you can accomplish transposing multiple columns. The SQL syntax will be a bit more complex as you will need to use several aggregate functions in the pivot clause. Note that you will need to provide aliases for each function because, otherwise, the query may result in an error.

Dynamic SQL

Dynamic Columns

Considering the change that occurs frequently within the columns, you can use dynamic SQL when dealing with the PIVOT function in your Oracle database. Dynamic queries are queries whose full text is not available until runtime. In this case, pivot values will be generated in the process, and you will need to apply the LISSTAG function. This solution, however, might turn out rather tedious, and hold up your process if you work with a complex query.

XML format

XML Format

Occasionally, you may not be well aware of what values are available in the column. In such cases, you can add the XML keyword to the PIVOT operator and gain the possibility to generate pivot results in the XML format. The XML notation allows you more flexibility as you will be able to indicate a special clause, ANY, or a subquery instead of having to enter precise values.


Unpivot Operator

It is often necessary to represent column-based data as rows, which leads to the use of the reverse command to PIVOT. Oracle provides the UNPIVOT operator, which allows us to break up the columns into separate rows by adding the columns you intend to unpivot in the IN clause. Note that although the UNPIVOT operator may be the opposite of PIVOT, you should not use it to reverse the result of pivoting as you risk losing the necessary details.

Creating a pivot table

Pivot tables are created from Query Builder. Open a query document to select it as a data source for a pivot table. In Database Explorer, select required tables from your database and drag-and-drop them to the query document. They are displayed as boxes with columns. In the table boxes, select the corresponding check boxes you want to use.

Switch to the Pivot Table view to see the pivot table template. The Data Source view opens automatically with the fields specified in our query document. To add fields to the pivot table, simply drag-and-drop them from the Data Source view to a required pivot table area.

Creating a Pivot Table in Oracle - Example

Reordering fields

Reordering fields is the key point in finding the best table layout to clearly understand data dependencies and benefit from them.

Simply drag-and-drop a field from one area of a pivot table to another in order to design its layout and rearrange their data the way you need.

You can easily swap row and column fields to display row field values in columns and column field values in rows.

Using Pivot Table in Oracle - Reordering Fields

Sorting and grouping fields

Sorting data in a pivot table allows displaying it in ascending or descending order.

You can group data in an Oracle pivot table using various predefined group modes. Grouping values of some field is done with a single click of your mouse. It will appear as a new sub-field, and you will be able to add it to a required area of your pivot table.

Values of date and time type can be grouped by years, months, quarters, weeks, days, etc. Numeric data can be grouped into numeric ranges. Text data can be grouped by the first letter.

Besides predefined group modes, you can create your own group criteria using the Collection Editor dialog box.

Pivot Table in Oracle - Sorting Fields Example

Filtering fields

Various types of filtering can be applied to display the required data in a pivot table.

To filter values of any field, click Filter on the field header, and in the opened dialog box, select only required values that you want to display. The data will be filtered according to the selected criteria.

You can add a filter field to filter all data in the pivot table. Drag-and-drop a required field from the Data Source view to the Filter area of the pivot table.

Pivot Table in Oracle with Example - Filtering Fields

Using summary functions to calculate custom totals

Pivot Table offers multiple summary functions that can be applied to calculate custom totals for column or row values. Custom totals are displayed in additional rows or columns highlighted in grey.

The Oracle pivot function counts the numeric values in the report using the SUM function by default. However, you can choose a different summary function:

  • Sum of all values
  • Average of values
  • Count of values
  • Maximum value
  • Minimum value
Oracle Pivot Query Example - Custom Totals


The Pivot table functionality is a relevant tool for easy and agile manipulation and processing of large data sets. The tool helps you improve data analysis efficiency, get deeper into relations and dependencies, extract the most useful information from your data, and generate it into a report. Along with the Pivot table tool, dbForge Studio for Oracle offers other useful database management and development features.

dbForge Studio for Oracle

Multifunctional Oracle GUI

Availability in the editions of dbForge Studio for Oracle


Pivot Table