Home > Database > Mysql Tutorial > mysql字符串替换简单介绍

mysql字符串替换简单介绍

WBOY
Release: 2016-06-07 17:53:09
Original
1194 people have browsed it

利用update与replace进行替换mysql中指定字符串了,有需要的朋友可参考。

说明:

table_name —— 表的名字
field_name —— 字段名
from_str —— 需要替换的字符串
to_str —— 替换成的字符串

例1

 代码如下 复制代码

UPDATE `table_name` SET `field_name` = replace (`field_name`,'from_str','to_str') WHERE `field_name` LIKE '%from_str%'

例2

比如你要将 表 tb1里面的 f1字段的abc替换为def

 代码如下 复制代码
UPDATE tb1 SET f1=REPLACE(f1, 'abc', 'def');

用法1.

 代码如下 复制代码
replace intoreplace into table (id,name) values(‘1‘,‘aa‘),(‘2‘,‘bb‘)

此语句的作用是向表table中插入两条记录。

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