Hmm... do you get paid to increase power consumption and execution time for queries?
Also:
Why all this text parsing?
Why relying on implicit type conversion and the auxiliary table content?
Why not using the standard function?
And if you really have to have a custom function - why go for a procedure with an out parameter?