If you save the value of X.ID||'%'
, you will probably find that it looks something like 1 %
(for id=1). Try putting compress
around X.ID||'%'
to remove that extra blanks, like so:
LIKE compress(X.ID || '%')
I assume you don't have any blank characters within your IDs.