Tune the inline queries first. How long are they taking individually ?

It looks like its possible to combine the two inline queries you have mentioned in this example in one query using either DECODE or CASE.