[英]remove everything but the last 7 characters in a record
I have table that contains a full mailing address for customers. 我有一个包含客户完整邮寄地址的表格。 I'd like to get rid of the whole address and only keep the postal code (last 7 characters, including the space).
我想摆脱整个地址,只保留邮政编码(最后7个字符,包括空格)。 I've searched for about and hour and can't figure it out.
我已经搜索了大约一小时,但无法弄明白。
Table Name: Customers Column: MailingAddress
So where I'd have 所以我在哪里
MailingAddress: 1234 Example Street, Cityplace T1U 2V4
I'd just like to have remaining 我只想留下来
MailingAddress: T1U 2V4
使用SUBSTR()
UPDATE Customers SET MailingAddress = SUBSTR(MailingAddress, -7, 7)
Or instead of SUBSTR()
, use the slightly simpler RIGHT()
to retrieve the n right-most characters of the expression. 或者代替
SUBSTR()
,使用稍微简单的RIGHT()
来检索表达式的n个最右边的字符。
UPDATE Customers SET MailingAddress = RIGHT(MailingAddress, 7)
...because I can personally never remember the order of arguments to SUBSTR()
or when negative values are legal. ...因为我个人永远不会记住
SUBSTR()
的参数顺序或负值是合法的。
只需查看文档即可:
http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_substr
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.