What do u want to acomplish thru this query. If u need the Max value, then then u shud use the MAX.
But here are a few things to consider.
1) Are XXX_NBR and YYY Indexed, if not try doing it.
2) If both the columns are indexed, is the predicate that brings back less rows executed first. If not try forcing the predicate that brings back more rows to execute last by concatenating Null to the corresponding host variable as here YYY = :WS-YYY || ''.