SUBSTRING_INDEX and concat can be used to split and splice MYSQL strings. The following describes the usage of the MYSQL string processing statement for your reference.
Split the content of a field and write it to other fields:
The field content is relatively regular, so select the substring_index function and use the concat string link function to effectively cooperate and achieve the final effect.
The telephone number is as follows: 010-88888882-5612
Divide the telephone number into the switchboard and extension number:
- select SUBSTRING_INDEX(phone,'-',2) as PNumber,
- SUBSTRING_INDEX(phone,'-', -1) as Ext,
- phone from tb_user where ucid = 271338
-
- +--------------+------+-------------------+
- | PNumber | Ext | phone |
- +--------------+------+-------------------+
- | 010-88888882 | 5612 | 010-88888882-5612 |
- +--------------+------+-------------------+
Change extension number to 1234:
- update tb_user set phone = concat(SUBSTRING_INDEX(phone,'-',2),'-','1234')
- where ucid = 271338 ;
The preceding MYSQL string segmentation and concatenation statements are described.
How to modify the default Character Set of mysql
View MySQL Default Character Set
Role of MySQL Foreign keys in Databases
How does MySQL Delete foreign key definitions?
How MySQL defines foreign keys