• 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)
  • 相关阅读:
    vue中的echarts实现宽度自适应
    前端执行vue打包后的dist文件
    nvm的使用和nrm的使用
    element-ui 中让el-container 高度自适应
    QQ登录报错:redirect uri is illegal(100010)
    纯CSS实现table固定thead,tbody进行滚动.html
    js实现垂直向上滚动
    我的 vscode 配置文件!
    CSS实现水平垂直居中的6种方式!
    百度API获取地点经纬度
  • 原文地址:https://www.cnblogs.com/wjw334/p/4284118.html
Copyright © 2020-2023  润新知