PIVOT and UNPIVOT

Published July 26, 2025 By Sai Sree Ram Gundepudi

PIVOT and UNPIVOT in Oracle

PIVOT

SELECT * FROM (
  SELECT department_id, job_id, salary FROM employees
)
PIVOT (
  SUM(salary) FOR job_id IN ('IT_PROG', 'SA_REP', 'FI_ACCOUNT')
);

UNPIVOT

SELECT * FROM (
  SELECT department_id, IT_PROG, SA_REP, FI_ACCOUNT FROM salary_summary
)
UNPIVOT (
  salary FOR job_role IN (IT_PROG AS 'IT_PROG', SA_REP AS 'SA_REP', FI_ACCOUNT AS 'FI_ACCOUNT')
);

Was this solution helpful?

Your feedback helps improve our technical knowledge repository.

Share this article