zoukankan      html  css  js  c++  java
  • sql 基础--mysql 5 (2)

    7.利用正则表达式筛选 regexp

    mysql> select * from pw_luck where msg regexp '1000';
    +-----+-----------+------+
    | uid | name      | msg  |
    +-----+-----------+------+
    |   7 | zhangsan7 | 1000 |
    |   8 | zhangsan8 | 1000 |
    |   9 | zhangsan9 | 1000 |
    |  10 | wang5     | 1000 |
    +-----+-----------+------+
    4 rows in set (0.00 sec)

      like 和 正则匹配 一般情况下不区分大小写  除非加入关键字 binary

    mysql> select * from pw_luck where name like 'wang%';
    +-----+--------+------+
    | uid | name   | msg  |
    +-----+--------+------+
    |   3 | wang5  | 1001 |
    |  10 | wang5  | 1000 |
    |  11 | wang5% | 2000 |
    |  12 | WANG5  | 1000 |
    +-----+--------+------+
    4 rows in set (0.00 sec)
    
    mysql> select * from pw_luck where name like binary 'wang%';
    +-----+--------+------+
    | uid | name   | msg  |
    +-----+--------+------+
    |   3 | wang5  | 1001 |
    |  10 | wang5  | 1000 |
    |  11 | wang5% | 2000 |
    +-----+--------+------+
    3 rows in set (0.00 sec)

      范围 []

    mysql> select * from pw_luck where name regexp 'zhangsan[1-9]'
        -> ;
    +-----+-----------+------+
    | uid | name      | msg  |
    +-----+-----------+------+
    |   7 | zhangsan7 | 1000 |
    |   8 | zhangsan8 | 1000 |
    |   9 | zhangsan9 | 1000 |
    +-----+-----------+------+
    3 rows in set (0.00 sec)
    mysql> select * from pw_luck where name regexp 'zhangsan[789]';
    +-----+-----------+------+
    | uid | name      | msg  |
    +-----+-----------+------+
    |   7 | zhangsan7 | 1000 |
    |   8 | zhangsan8 | 1000 |
    |   9 | zhangsan9 | 1000 |
    +-----+-----------+------+
    3 rows in set (0.00 sec)
    zhangsan[789]也可以写成 zhangsan[7|8|9]

    转义字符: | 【】 - . 等

    元字符:* 0个或多个
        + 1个或多个
        ? 0个或1个
        {n} 指定数目
        {n,}
        {n,m} 范围
    定位符 ^开始位置 (【】外,【】内是非的意思)
        $文本结尾

    mysql> select * from pw_luck where name regexp '^[l]';
    +-----+------+------+
    | uid | name | msg  |
    +-----+------+------+
    |   2 | lisi | 1001 |
    +-----+------+------+
    1 row in set (0.00 sec)
    
    mysql> select * from pw_luck where name regexp 'l';
    +-----+--------+------+
    | uid | name   | msg  |
    +-----+--------+------+
    |   0 | Wilson |  100 |
    |   2 | lisi   | 1001 |
    +-----+--------+------+
    2 rows in set (0.00 sec)
  • 相关阅读:
    PHPCMS V9 导航栏当前栏目高亮
    phpcms v9栏目列表调用每一篇文章内容方法
    PHPCMS V9 为今天或几天前文章加new
    vue.js路由参数简单实例讲解------简单易懂
    vue组件知识总结
    vue.js 利用组件之间通讯,写一个弹出框例子
    vue.js组件之间通讯--父组件调用子组件的一些方法,子组件暴露一些方法,让父组件调用
    vue.js组件之间的通讯-----父亲向儿子传递数据,儿子接收父亲的数据
    vue.js通讯----父亲拿儿子的数据
    git常见操作---由简入深
  • 原文地址:https://www.cnblogs.com/wjw334/p/4284118.html
Copyright © 2011-2022 走看看