1. Get rid of all advertisements and get unlimited access to documents by upgrading to Premium Membership. Upgrade to Premium Now and also get a Premium Badge!

Convert Column Values to Row Values with simple SQL

Discussion in 'SQL PL/SQL' started by victoryhendry, Feb 20, 2012.

  1. I have a normal table like step 1 and I want to get a output like step 2. Please try to help me for the same in a simple sql example pls..( want to convert column values to row )

    Step 1)

    Table Name: Rat_table
    ------------------------------------------


    year rating_name
    ------ -----------
    2011 'Sucessful'

    2010 'Not Rated'

    Step 2)

    Table Name: Rat_table
    ------------------------------------------

    rating_name 'Sucessful' 'Not Rated'
    year 2011 2010


    Thanks and Regards,

    VetriVel K-Dharmapuri(Oracle)
     
  2. zargon

    zargon Community Moderator Forum Guru

    Messages:
    2,347
    Likes Received:
    348
    Trophy Points:
    1,430
    Location:
    Aurora, CO
    Please post the version of Oracle you are using as it does make a huge difference in how your question will be answered.
     
  3. rajavu

    rajavu Forum Guru

    Messages:
    815
    Likes Received:
    52
    Trophy Points:
    610
    Location:
    @ Bangalore , India
  4. tj.abrahamsen

    tj.abrahamsen Active Member

    Messages:
    10
    Likes Received:
    1
    Trophy Points:
    90
    Location:
    Utah
    VentriVel -

    Tim Hall has a nice article/post about PIVOTing and UNPIVOTing. If you Google this text "oracle-base +unpivot", you should be able to find his article.

    As David has already mentioned, your version of Oracle matters, since I believe the PIVOT and UNPIVOT operators were introduced in 11g.

    Also, to get general ideas you might want to Google using words like "transpose", etc. I am not going to be a spammer putting a link in here, but if you find your way to my blog you will find a post about transposing rows into columns there.

    There is a lot of good information on Google/

    Hope this helps,
    TJ