开发者

How to get last 12 digits from a string in MySQL?

开发者 https://www.devze.com 2022-12-28 05:40 出处:网络
How would I get last 12 digits of a string using mysql? Let\'s say I have a varchar field with a tracking number, that may be anywhere from 5 to 20 varchars long.But I only need to select last 12 dig

How would I get last 12 digits of a string using mysql?

Let's say I have a varchar field with a tracking number, that may be anywhere from 5 to 20 varchars long. But I only need to select last 12 digits or less if there are less.

so in a field = 12345678123456789012

I would only need to get what's in brackets

field = 12345678[123456789012]

I saw a few examples开发者_JAVA技巧 using mid, etc, but they dont' produce the desired result or I can't find an example that makes sense :-(

Thank you.


SELECT RIGHT(field, 12);


Nick,

Try using the RIGHT(str, len) function.

http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_right

I'm not sure of the semantics if the string is shorter than length as I don't have access to MySQL but it might do what you're looking for.

0

精彩评论

暂无评论...
验证码 换一张
取 消