• mysql学习--mysql必知必会1


    

    例如以下为mysql必知必会第九章開始:

    正則表達式用于匹配特殊的字符集合。mysql通过where子句对正則表達式提供初步的支持。

    keywordregexp用来表示后面跟的东西作为正則表達式处理。

    (.)是正則表達式的一个符号,表示匹配随意一个字符:

    mysql> select prod_name
        -> from products
        -> where prod_name regexp '.000'
        -> order by prod_name;
    +--------------+
    | prod_name    |
    +--------------+
    | JetPack 1000 |
    | JetPack 2000 |
    +--------------+
    2 rows in set (0.14 sec)
    

    |匹配符:

    表示匹配当中之中的一个

    mysql> select prod_name
        -> from products
        -> where prod_name REGEXP '1000|2000'
        -> ORDER BY prod_name;
    +--------------+
    | prod_name    |
    +--------------+
    | JetPack 1000 |
    | JetPack 2000 |
    +--------------+
    2 rows in set (0.00 sec)
    


    []匹配符: 匹配几个字符之中的一个

    2 rows in set (0.00 sec)
    
    mysql> select prod_name
        -> from products
        -> where prod_name regexp '[123] Ton'
        -> ;
    +-------------+
    | prod_name   |
    +-------------+
    | 1 ton anvil |
    | 2 ton anvil |
    +-------------+
    2 rows in set (0.00 sec)
    
    mysql> select prod_name from products where prod_name regexp '[1-5] Ton';
    +--------------+
    | prod_name    |
    +--------------+
    | .5 ton anvil |
    | 1 ton anvil  |
    | 2 ton anvil  |
    +--------------+
    3 rows in set (0.02 sec)
    


    (^)否定匹配符:

    mysql> select prod_name from products where prod_name regexp '[^1-3] Ton';
    +--------------+
    | prod_name    |
    +--------------+
    | .5 ton anvil |
    +--------------+
    1 row in set (0.00 sec)
    


    匹配特殊字符,必须用\为前导。

    mysql> select prod_name from products where prod_name regexp '\.' ;
    +--------------+
    | prod_name    |
    +--------------+
    | .5 ton anvil |
    +--------------+
    1 row in set (0.00 sec)
    


    匹配字符类:

    mysql> select prod_name from products where prod_name REGEXP '\([0-9] sticks?\)' order by prod_name;
    +----------------+
    | prod_name      |
    +----------------+
    | TNT (1 stick)  |
    | TNT (5 sticks) |
    +----------------+
    2 rows in set (0.05 sec)
    
    mysql> select prod_name from products where prod_name REGEXP '[[:digit:]]{4}' order by prod_name;
    +--------------+
    | prod_name    |
    +--------------+
    | JetPack 1000 |
    | JetPack 2000 |
    +--------------+
    2 rows in set (0.00 sec)
    


     

    定位符使用方法:

    mysql> select prod_name
        -> from products
        -> where prod_name REGEXP '^[0-9\.]'
        -> order by prod_name;
    +--------------+
    | prod_name    |
    +--------------+
    | .5 ton anvil |
    | 1 ton anvil  |
    | 2 ton anvil  |
    +--------------+
    3 rows in set (0.00 sec)
    


    以上都是mysql正則表達式的使用方法。

  • 相关阅读:
    空间轴向对齐变换
    购买服务器,搭建服务器服务器
    软件工程第四次作业:猫狗大战挑战赛
    软件工程第三次作业:卷积神经网络
    04卷积神经网络
    03深度学习的数学基础
    mfc回显信息
    软件工程第二次作业:深度学习和pytorch基础
    python 机器学习第二章(感知器学习算法)
    python 机器学习第一章
  • 原文地址:https://www.cnblogs.com/mengfanrong/p/3774722.html
Copyright © 2020-2023  润新知