The error:
ERROR [HY000] ERROR: Bad numeric input format
Is caused because you feeding letters into TO_NUMBER
. You are feeding it 99G99
which is not a number.
The program tries to tell you it's not a number by telling you that the numeric input format is bad, as the error very clearly says.