Ok,
so I find it hard to believe if you execute the exact full sql generated from this, you would get the result you want from oracle.
first thing I notice (might not be it, but if not, please explain why this works) :
it looks like you are missing 2 closing round brackets at the end of line 22