I think this a problem called as Pivoting.
DO search for pivoting in asktom.oracle.com
Hope this will help you.
-Sameer