It is best to post your question to Oracle related forum. This newsgroup is dedicated to SQL Server and even there are
folks around here with Oracle knowledge you can get better answer in Oracle dedicated forum.
Instead of doing a loop seems you can use unpivoting technique to get the results you need.
--
Plamen Ratchev
http://www.SQLStudio.com