Avatar of Wilder1626
Wilder1626
Flag for Canada asked on

Oracle Transpose query

Hi,

I would like to transport  row to column in Oracle query.

I have this query that i use:

Select Customer, Customer_status, Pickup_location, Pickup_Location_Status from dbCust;

Open in new window

The result give something like this:

I would like to transpose it to:

How can i do that?


Thank you for your help


Oracle DatabaseSQL

Avatar of undefined
Last Comment
Wilder1626

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
ste5an

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Wilder1626

ASKER
Thanks. This is perfect .
Wilder1626

ASKER
I may have a problem. I get this error: ORA-01748: only simple column names allowed here
What if i have more than 1 record. Ex:


How can i transpose like that?
Is that even possible?
ste5an

This is not an unpivot.  It is an two step operation of unpivot and pivot again. But then you probably need dynamic SQL.

The simple solution, e.g. when there is no ID:

SELECT  *
FROM    yourTable
UNPIVOT
(
    COLUMN_VALUE
    FOR COLUMN_NAME IN (
        "CUSTOMER_STATUS",
        "PICKUP_LOCATION",
        "PICKUP_LOCATION_STATUS"
    )
);

Open in new window

This will leave the CUSTOMER column as identificator.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
Wilder1626

ASKER
Thanks. Let me try a few thing.