zoukankan      html  css  js  c++  java
  • MYSQL———正则表达式查询!

    在使用select查询的过程中,有时会用到正则表达式对结果进行查询,将学习到的内容进行总结!

    一 语法结构如下:

      

    二 常用匹配方式进行示例说明

       首先创建表student,表的结构如下:

       

     1·^:查询student表中sname列已‘王’开始的姓名

    select sname from student where sname regexp '^王';    #查出结果:王丽.王芳

     

     2·$:查询student表中sname列已‘文’结束的姓名 

    select sname from student where sname regexp '文$';  #查出结果:尚文

     

     3. · :查询student表中sname的开始字符是‘李’,后面不做限制的姓名

    select sname from student where sname regexp '李.'; #查出结果:李军

     

     4· [字符集合]:查询student表中sbirthday列,年份中包含8或者5的年份

    select sbirthday from student where sbirthday regexp '[85]';  #查出结果1798,1795

     

     5.[^字符集合]:查询student表中sbirthday列,年份除了1976的其余年份

    select sbirthday from student where sbirthday regexp '[^1976]';  #查出结果:1978,1974,1975

     

     6. s1|s2|s3:查询student表中sbirthday列,包含76|75|78的年份

    select sbirthday from student where sbirthday regexp '76|75|78';   #查出结果:1976.1978.1975.1976

     

     7·×:查询student表中sname 列,‘文’出现的sname

    select sname from student where sname regexp '文*';   #查出结果:尚文,说明:注意使用×是指查询的字符串可以有,也可以出现1次或者多次

     

     8.+:查询student表中sname 列,‘文’出现的sname

    select sname from student where sname regexp '文+';  #查出结果:尚文,说明:注意使用+是指查询的字符串至少要出现1次

     

     9.字符{n}:查询student表中sname 列,‘文’出现1次的sname

     select sname from student where sname regexp '文{1}'; #查出结果:尚文,查询出了文出现1次的姓名,将1改为2,将返回NULL,因为student表中sname列没有文出现过2次的姓名

     

     10. 字符{m,n}:查询student表中sbirthday 列,‘7’出现至少2次,最多不超过3的年份

    select sbirthday from student where sbirthday regexp '7{2,3}';  #查出结果:1977,1977
  • 相关阅读:
    移动端应用rem定义相对长度单位
    ionic4(angular) 生成browser平台的(webApp)在手机QQ浏览器不更新页面
    解决 git bash命令行执行git命令一直报错 segmentation fault
    MACBOOK OSX升级到10.15.3 Catalina 后 photoshop CS6(32位)不能用了
    自制操作系统笔记-第三章
    自制操作系统笔记-第2章
    自制操作系统笔记-第一章
    Vue学习笔记
    解决 MAC 终端上每次打开新窗口手动执行source ~/.bash_profile导出环境变量
    HTTPS的安全性
  • 原文地址:https://www.cnblogs.com/syw20170419/p/6912309.html
Copyright © 2011-2022 走看看