Mysql string segmentation and concatenation functions _ MySQL

Source: Internet
Author: User
How can I implement a MySQL string that separates the content of a field and writes it to other fields? Use SUBSTRING_INDEX and CONCAT to implement this function. SUBSTRING_INDEX and CONCAT can be used to split and splice MYSQL strings. the following mysql string

How can I implement a MySQL string that separates the content of a field and writes it to other fields? Use SUBSTRING_INDEX and CONCAT to implement this function.

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. the telephone number is divided 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 = CPNCAT (SUBSTRING_INDEX (phone, '-', 2), '-', '123 ')

WHERE ucid = 271338;

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.