简体   繁体   English

删除记录中除最后7个字符外的所有内容

[英]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.

相关问题 删除 MySql 中 &lt;&gt; 字符内的所有内容 - Remove everything inside <> characters in MySql 删除最后一个斜杠以及该MySQL查询之后的所有内容 - Remove last last slash and everything after that MySQL query MySQL查询-声明省后从记录中删除所有内容 - mySQL query - remove everything from record after the province is stated 如果最后 3 个字符是某个字符串,则排除记录,仅当倒数第四个字符是特定字符时 - Exclude record if last 3 characters is some string, only if the fourth characters from the last is a specific characters mysql删除最后一个字符是字符,如果它的号码 - mysql remove last characters is character if its number 我无法显示表格中的所有内容,仅显示最后一条记录 - I can't display everything from my table, it only displays the last record MySQL 从要插入的新记录中的字段中删除尾随换行符 - MySQL remove trailing newline characters from a field in a new record to be inserted MySQL / MariaDB - 从数据库中删除除每天最后一条记录之外的所有记录 - MySQL / MariaDB - Remove all but last record per day from database CodeIgniter活动记录-删除除最后10个匹配条件外的所有条件 - CodeIgniter Active Record - Remove all but last 10 that match criteria 查询以删除字符串中最后一个逗号后的所有字符 - query to remove all characters after last comma in string
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM