1、mysql 模糊匹配 like 与 not like 用法 :

SELECT * FROM `user` where `nickname` LIKE '%测试%'

SELECT * FROM `user` where `nickname` not  LIKE '%测试%'

2、mysql 批量替换replace函数用法 :

  • 替换某个字段,replace可以替换某个字段中的指定的某个部分,replace(column_name,oldregexstr,newreplacestr)
  • 替换表一行,如果原表中有该条数据,那么会将该条数据删除;如果原表中没有该条数据,则会插入指定值

mysql> select replace('12_34_56','_','&');
+-----------------------------+
| replace('12_34_56','_','&') |
+-----------------------------+
| 12&34&56                    |
+-----------------------------+

mysql> select * from user;
+----+--------------+---------------+------+-------------+----------+---------+
| ID | user_id_tree | nickname      | NAME | DESCRIPTION | QUANTITY | created |
+----+--------------+---------------+------+-------------+----------+---------+
|  1 | 1_2_3        | 测试_kong_123 | 1111 | NULL        | NULL     | NULL    |
+----+--------------+---------------+------+-------------+----------+---------+
1 row in set

mysql>    UPDATE user set `user_id_tree`= replace( `user_id_tree`, '_2_3', '&2&3')  where `id`=1;
Query OK, 1 row affected
Rows matched: 1  Changed: 1  Warnings: 0
mysql> select * from user;
+----+--------------+---------------+------+-------------+----------+---------+
| ID | user_id_tree | nickname      | NAME | DESCRIPTION | QUANTITY | created |
+----+--------------+---------------+------+-------------+----------+---------+
|  1 | 1&2&3        | 测试_kong_123 | 1111 | NULL        | NULL     | NULL    |
+----+--------------+---------------+------+-------------+----------+---------+
1 row in set

mysql> replace into user (name) value (222);
Query OK, 1 row affected
mysql> select * from user;
+----+--------------+---------------+------+-------------+----------+---------+
| ID | user_id_tree | nickname      | NAME | DESCRIPTION | QUANTITY | created |
+----+--------------+---------------+------+-------------+----------+---------+
|  1 | 1&2&3        | 测试_kong_123 | 1111 | NULL        | NULL     | NULL    |
|  9 | NULL         | NULL          | 222  | NULL        | NULL     | NULL    |
+----+--------------+---------------+------+-------------+----------+---------+
2 rows in set

3、备注:mysql 帮忙命令可以查看详细的命令说明,使用help或问号

比如查看replace函数的使用说明:help replace ? replace

root@localhost : xxx_server 10:52:03>? replace;
Name: 'REPLACE'
Description:
Syntax:
REPLACE [LOW_PRIORITY | DELAYED]
    [INTO] tbl_name
    [PARTITION (partition_name [, partition_name] ...)]
    [(col_name [, col_name] ...)]
    {VALUES | VALUE} (value_list) [, (value_list)] ...

REPLACE [LOW_PRIORITY | DELAYED]
    [INTO] tbl_name
    [PARTITION (partition_name [, partition_name] ...)]
    SET assignment_list

REPLACE [LOW_PRIORITY | DELAYED]
    [INTO] tbl_name
    [PARTITION (partition_name [, partition_name] ...)]
    [(col_name [, col_name] ...)]
    SELECT ...

value:
    {expr | DEFAULT}

value_list:
    value [, value] ...

assignment:
    col_name = value

assignment_list:
    assignment [, assignment] ...

REPLACE works exactly like INSERT, except that if an old row in the
table has the same value as a new row for a PRIMARY KEY or a UNIQUE
index, the old row is deleted before the new row is inserted. See [HELP
INSERT].

REPLACE is a MySQL extension to the SQL standard. It either inserts, or
deletes and inserts. For another MySQL extension to standard SQL---that
either inserts or updates---see
http://dev.mysql.com/doc/refman/5.7/en/insert-on-duplicate.html.

DELAYED inserts and replaces were deprecated in MySQL 5.6. In MySQL
5.7, DELAYED is not supported. The server recognizes but ignores the
DELAYED keyword, handles the replace as a nondelayed replace, and
generates an ER_WARN_LEGACY_SYNTAX_CONVERTED warning. ("REPLACE DELAYED
is no longer supported. The statement was converted to REPLACE.") The
DELAYED keyword will be removed in a future release.

*Note*:

REPLACE makes sense only if a table has a PRIMARY KEY or UNIQUE index.
Otherwise, it becomes equivalent to INSERT, because there is no index
to be used to determine whether a new row duplicates another.

Values for all columns are taken from the values specified in the
REPLACE statement. Any missing columns are set to their default values,
just as happens for INSERT. You cannot refer to values from the current
row and use them in the new row. If you use an assignment such as SET
col_name = col_name + 1, the reference to the column name on the right
hand side is treated as DEFAULT(col_name), so the assignment is
equivalent to SET col_name = DEFAULT(col_name) + 1.

To use REPLACE, you must have both the INSERT and DELETE privileges for
the table.

If a generated column is replaced explicitly, the only permitted value
is DEFAULT. For information about generated columns, see
http://dev.mysql.com/doc/refman/5.7/en/create-table-generated-columns.h
tml.

REPLACE supports explicit partition selection using the PARTITION
keyword with a list of comma-separated names of partitions,
subpartitions, or both. As with INSERT, if it is not possible to insert
the new row into any of these partitions or subpartitions, the REPLACE
statement fails with the error Found a row not matching the given
partition set. For more information and examples, see
http://dev.mysql.com/doc/refman/5.7/en/partitioning-selection.html.

URL: http://dev.mysql.com/doc/refman/5.7/en/replace.html

mysql模糊匹配like及批量替换replace的更多相关文章

  1. 在Visual Studio中使用正则表达式匹配换行和批量替换

    系统环境:Windows 8.1 Enterprise Update 2 x64 开发环境:Mircosoft Visual Studio Ultimate 2013 Update 2 RC 问题:如 ...

  2. Mysql 模糊匹配和转义字符

    首先创建一个测试表: insert into test(tt) values('\\\\172.18.28.153'); 现在我想使用模糊匹配,查出以 “\\172” 开头的字符串. 需要使用like ...

  3. MySQL模糊匹配查询like、regexp、in

    MySQL提供标准的SQL模式匹配,以及一种基于像Unix实用程序,如:vi.grep和sed的扩展正则表达式模式匹配的格式 一.SQL模式(% ,_) SQL的模式匹配允许你使用“_”匹配任何单个字 ...

  4. mysql模糊匹配

    select * from tableName where column like ""; select * from tableName where column regexp ...

  5. Mysql 模糊匹配(字符串str中是否包含子字符串substr)

    1.LIKE 通常与 % 一同使用,类似于一个元字符的搜索.若substr不在str中,则返回0. 2.INSTR(str,substr) 返回字符串 str 中子字符串的第一次出现位置.若subst ...

  6. mysql学习2:模糊匹配查询like,regexp,in

    mysql模糊匹配查询like,regexp,in   摘要 内容比较简单,无摘要.   关键词 模糊查询  like  regexp  in  contact   正文 下图是示例用到的数据表信息 ...

  7. Pycharm小技巧--使用正则进行查找和批量替换

    分享一个Pycharm中使用正则的分组匹配来进行批量替换的小技巧 例如,我现在需要把HTML文件中的静态文件得到路径全部替换为django模板引用路径的格式 修改为类似这样的格式: {% static ...

  8. replace() MySQL批量替换指定字段字符串

    mysql replace实例说明: UPDATE tb1 SET f1=REPLACE(f1, 'abc', 'def'); REPLACE(str,from_str,to_str) 在字符串 st ...

  9. mysql函数之七:replace() MySQL批量替换指定字段字符串

    mysql replace实例说明: UPDATE tb1 SET f1=REPLACE(f1, 'abc', 'def'); REPLACE(str,from_str,to_str) 在字符串 st ...

随机推荐

  1. 19 01 03 css 中 reset 模块 设置

    主要就是让到时候 打入代码时候  把一些bug去除   或者 让一些固有的格式取消 /* 将标签默认的间距设为0 */ body,p,h1,h2,h3,h4,h5,h6,ul,dl,dt,form,i ...

  2. python 发送邮件,并且带附件

    #!/usr/bin/pythonfrom email.mime.text import MIMETextfrom email.mime.multipart import MIMEMultiparti ...

  3. CTF-域渗透--HTTP服务--命令注入2

    开门见山 1. 启动metasploit 2. 设置参数参数选项 3. 查看最后设置后的结果 4. 启动监听 5. 使用msfvemon制作webshell 6. 开启apache服务 7. 使用ba ...

  4. java8中的map 和reduce

    map 1.使用map让集合里面的数字翻倍. List<Integer> numbers = Lists.newArrayList(1,2,3,4,5);List<Integer&g ...

  5. grid布局——从入门到放弃

    基本知识 CSS grid 布局有两个核心组成部分:wrapper(网格容器,父元素)和items(网格项,子元素). 基本属性 属性 含义 display: grid 网格布局(父元素设置) gri ...

  6. webapi 传入参数校验

    /// <summary> /// 传入参数校验过滤器 /// </summary> public class ValidateReqModelFilter : ActionF ...

  7. Codeforces 997A Convert to Ones(思维)

    https://codeforces.com/problemset/problem/997/A 题目大意: 给定一串0-1序列,定义两种操作: 操作一:选取一连续串倒置. 操作二:选取一连续串把进行0 ...

  8. 1-3.监督学习(supervised learning)

    定义:监督学习指的就是我们给学习算法一个数据集,这个数据集由“正确答案”组成,然后运用学习算法,算出更多的正确答案.术语叫做回归问题 [监督学习可分为]:回归问题.分类问题.两种 例:一个学生从波特兰 ...

  9. 2020/1/28 PHP代码审计之代码执行漏洞

    0x00代码执行原理 应用程序在调用一些能够将字符串转换为代码的函数(如PHP中的eval)时,没有考虑用户是否控制这个字符串,将造成代码执行漏洞. 该漏洞主要存在于eval().assert().p ...

  10. neo4jcypher基本语句

    create (:患者)-[rl:likes]-> (dept:Dept ) ///////////////关系 (STARTNODE)MATCH (video1:YoutubeVideo1)- ...