Several methods to find and replace fixed strings in mysql fields_PHP tutorial

WBOY
Release: 2016-07-21 15:16:21
Original
1136 people have browsed it

Our requirement is to remove China from the address field and set the province (province_id) field according to the address field.

First, to find a string, we can use replace in mysql, which is also mentioned in this blog. For details, see: http://www.jb51.net/article/31374.htm

Okay, let’s remove the character "China".

update table set address = replace(address,'China','')

Second, update the province_id field based on the first characters of the address field. The SQL statement is as follows

UPDATE table SET province_id=11 where LEFT(address,2)='Fujian'

The LEFT function of mysql is used here to find the first two characters of the address character and determine whether it is 'Fujian' If so, SQL will update the province_id field to 11. The 11 here is the ID corresponding to the province table Fujian.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/325950.htmlTechArticleOur requirement is to remove China from the address field and set the province (province_id) according to the address field ) field. First, to find the string, we can use repla in mysql...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!