Looking into the Oracle CHAR issue yesterday (GEOT-2293) I noticed that when an attribute used for filtering is not part of the returned feature type, the encoder does not get enough context to decide what the type of the attribute is.
The issue is simple, the filtered feature type gets passed down to the encoder instead of the full feature type, resulting in the filtering attribute information being missing.
This in turn makes the literal encoder try to guess the type, with the usual problems when strings like "021" get turned into numbers and then compared against strings (which sometimes works, sometimes does not).
The patch is simple, alwasy grab the full feature type when doing sql encoding. Actually, that is only needed when doing selects, so the patch is quite small. There is a test for this already, but it's evidently not covering all cases (and to be frank, I noticed the problem, but even Oracle was happy
enough to compare the string with a number, and it was still doing the right thing).