Finding last character of a string

Database
Enthusiast

Finding last character of a string

Hi,

Do we have some different approch to get last character of a string ( Fix length/ Variable length both ) apart from using substr ?

Thanks

Nagendra

Tags (1)
1 REPLY
Enthusiast

Re: Finding last character of a string

Substr is really about the only function that lets you pull a single value out, especially depending on what version of the database you are on.  I guess you could build a UDF that might do something, but if you have a native feature that can do the job, why not use it.   using a combination of trim, character_length, position, and substr you can pretty much do what you want.  There isn't a feature/function that I am aware of that will let you get the last character of a string at least natively in the database.

If your on 14.10 or 15.00 you might try strtok which can parse a string, but not sure if it can parse things like a word or not (never tried it).

Is there a reason you don't want to use substr?