定制开发SQL学习笔记——REGEXP运算符

REGEXP运算符,定制开发是正则表达式(regular expression)的缩写,定制开发正则表达式在搜索字符定制开发串时非常强大,定制开发下面是关于它的应用

1.查找名字中包含field的顾客

  1. select *
  2. from customers
  3. where last_name like '%field%'

运用REGEXP运算符,可以这样写,同样可以得出数据

  1. select *
  2. from customers
  3. where last_name regexp 'field'

2.查找姓氏以Brush开头的顾客

 ^表示查找的字符串必须以什么开头

  1. select *
  2. from customers
  3. where last_name regexp '^brush'

 

 

 3.查找姓氏以field结尾的顾客

$表示查找的字符串必须以什么结尾

  1. select *
  2. from customers
  3. where last_name regexp 'field$'

3.查找姓氏包含field或者mac的顾客

|符号表示多个搜寻模式

  1. select *
  2. from customers
  3. where last_name regexp 'brush|mac'

4.查找以brush开头,或者包含mac,或者包含的顾客

  1. select *
  2. from customers
  3. where last_name regexp '^brush|mac|rose'

 

5.查找姓氏包含e,且前面要有g或i或m

  1. select *
  2. from customers
  3. where last_name regexp '[gim]e'

 

6.查找姓氏包含e,且后面要有a但h中的一个字母

  1. select *
  2. from customers
  3. where last_name regexp 'e[a-h]'

总结:

^表示字符串开头

¥表示字符串结尾

|表示逻辑上的or,可以给出多个搜索模式

[]表示任意在括号里列举的单字符

[-]表示任意在括号内范围内的单字符

练习

1.获取名字是Elka或者Ambur的顾客

  1. select *
  2. from customers
  3. where first_name regexp 'elka|ambur'

 2.返回姓氏以ey或者on结尾的顾客

  1. select *
  2. from customers
  3. where last_name regexp 'ey$|on$'

 3.获取姓氏以my打头,或者包含se的顾客

  1. select *
  2. from customers
  3. where last_name regexp '^my|se'

 4.返回顾客,姓氏包含b,然后是r或者u

  1. select *
  2. from customers
  3. where last_name regexp 'b[ru]'

 

网站建设定制开发 软件系统开发定制 定制软件开发 软件开发定制 定制app开发 app开发定制 app开发定制公司 电商商城定制开发 定制小程序开发 定制开发小程序 客户管理系统开发定制 定制网站 定制开发 crm开发定制 开发公司 小程序开发定制 定制软件 收款定制开发 企业网站定制开发 定制化开发 android系统定制开发 定制小程序开发费用 定制设计 专注app软件定制开发 软件开发定制定制 知名网站建设定制 软件定制开发供应商 应用系统定制开发 软件系统定制开发 企业管理系统定制开发 系统定制开发