MySQL string segmentation and concatenation statements

Source: Internet
Author: User
Tags mysql delete

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:

 
 
  1. select SUBSTRING_INDEX(phone,'-',2) as PNumber,   
  2.        SUBSTRING_INDEX(phone,'-', -1) as Ext,   
  3.        phone from tb_user   where ucid = 271338 
  4.  
  5. +--------------+------+-------------------+  
  6. | PNumber      | Ext | phone             |  
  7. +--------------+------+-------------------+  
  8. | 010-88888882 | 5612 | 010-88888882-5612 |  
  9. +--------------+------+-------------------+  

Change extension number to 1234:

 
 
  1. update tb_user set phone = concat(SUBSTRING_INDEX(phone,'-',2),'-','1234')  
  2. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.