Home > Database > Mysql Tutorial > body text

mysql字符串分割和拼接函数介绍_MySQL

WBOY
Release: 2016-06-01 13:18:33
Original
2023 people have browsed it

mysql字符串

MySQL字符串如果需要将某个字段里的内容进行分割并写入到其他字段中,应该如何实现呢?使用SUBSTRING_INDEX 及CONCAT就可以实现这个功能。

  SUBSTRING_INDEX 及CONCAT可以实现MYSQL字符串分割并拼接,下面就对该MYSQL字符串处理语句的用法进行详细介绍,供您参考。

  将某个字段里的内容进行分割并写入到其他字段中:

  字段内容比较有规律,所以选择SUBSTRING_INDEX函数并配合CONCAT字符串链接函数进行有效的配合和实现最终效果。

  有电话号码如下: 010-88888882-5612,将电话号码划分为总机和分机号:

  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 |

  +--------------+------+-------------------+

  变更分机号码为1234:

  UPDATE tb_user SET

  phone=CPNCAT( SUBSTRING_INDEX( phone,'-',2 ), '-', '1234' )

  WHERE ucid = 271338;

Related labels:
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!