What is the function of the pivot function in Oracle?
The PIVOT function in Oracle is used to transform row data into column data. It aggregates row data based on specified column values and displays the aggregated result in a column format.
Specifically, the PIVOT function can group row data in a table according to a specified column and then transform these grouped row data into column data. Typically, the PIVOT function needs to be used in conjunction with an aggregate function to aggregate the data during the transformation process.
Here is the syntax for the PIVOT function:
SELECT * FROM (
SELECT <select_list>, <pivot_column>, <value_column>
FROM <table_name>
)
PIVOT (
<aggregate_function>(<value_column>)
FOR <pivot_column>
IN (<value_list>)
)
Here,
By using the PIVOT function, it is easy to convert row data into column data, making it more visually appealing in query results.