There are a few ways to work around this issue. One way is to use the PIVOT XML statement. The PIVOT XML statement allows you to use a dynamic value in the IN clause. However, the output of the PIVOT XML statement is not as readable as the output of the PIVOT statement.
Here is an example of how to use the PIVOT XML statement to pivot the values in the A column by the values in the CL column:
SELECT
XMLTYPE(pivot_xml(sum(A) FOR B IN (CL))) AS pivot_xml
FROM
my_table
The output of this query would be an XML document that contains the pivoted data. The XML document would be in a format that is not very readable, but it can be parsed by other applications.
Another way to work around this issue is to use dbForge Studio for Oracle, which helps to create a pivot with dynamic values by allowing you to use dynamic SQL in the pivot table layout. Dynamic SQL is a type of SQL that is not fully defined until runtime. This means that you can use dynamic SQL to create a pivot table that uses values that are not known until the pivot table is created.
For example, you could use dynamic SQL to create a pivot table that uses the current year as the column values. The following is an example of how to do this:
SELECT
year,
SUM(salary) AS total_salary
FROM
employees
WHERE
year = :year
PIVOT
(
SUM(salary)
FOR year IN (:years)
)
In this example, the :year
and :years
parameters are dynamic values. The :year
parameter is the current year, and the :years
parameter is a list of years that the pivot table should use.
When the pivot table is created, the :year
and :years
parameters will be replaced with the actual values. This will allow the pivot table to use the current year as the column values, and to use the list of years that you specified as the possible values for the column values.
This tool makes it easy to use dynamic SQL in pivot tables. You can simply drag and drop the dynamic SQL into the pivot table layout, and dbForge Studio for Oracle will take care of the rest.