Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Pivot without using aggregate function

M Prasad-OracleAug 30 2019 — edited Aug 30 2019

HI Expert,

My data set is as below:

Name       Label     History                    User         Type      Privileges       Owner      Object      Grantor Grantable

Target1      Label2      UNCHANGED      ADMIN      USER      INSERT      ADMIN      WIKI      ADMIN      NO

Target1      Label1      UNCHANGED      ADMIN      USER      INSERT      ADMIN      WIKI      ADMIN      NO

Target1      Label2      UNCHANGED      ADMIN      USER      SELECT      ADMIN      WIKI      ADMIN      NO

Target1      Label1      UNCHANGED      ADMIN      USER      SELECT      ADMIN      WIKI      ADMIN      NO

..

....

DESIRED OUTPUT:

Name           History              Object      Type      User_Label1    User_Label2  Pri_Label1       Priv_Label2      Owner_Label1      Owner_Label2      Grantor_Label1 Grantor_Label2      GrantableLabel1 GrantableLabel2

Target1      UNCHANGED      WIKI       USER      ADMIN                ADMIN           INSERT           INSERT               ADMIN                     ADMIN                 ADMIN                ADMIN                     NO                     NO

Target1      UNCHANGED      WIKI      USER      ADMIN                 ADMIN           SELECT           SELECT             ADMIN                     ADMIN                ADMIN                ADMIN                     NO                     NO

..

I tried to use PIVOT with aggregate function but it picks one (min/max) record of the Label  and CASE statement returns NULL , if data not present for Label.

Basically, We need to display data for Label1 and Label2.

Target,Label,History, Object are constant and remaining columns data will change for the labels.

Please provide the pointers to achieve the desired result.

Comments
Post Details
Added on Aug 30 2019
3 comments
557 views