in reply to Code refactoring challenge

Some fun for the weekend.. I thought people might like to join in my code refactoring (I was just supposed to "make it work" for oracle, but somehow I got carried away, you will see why.. )

Can you simplify the following: (...big snip...)

That sounds too much like real work.