当前位置:网站首页>SQL学习笔记——REGEXP运算符
SQL学习笔记——REGEXP运算符
2022-08-02 14:40:00 【m0_67402125】
REGEXP运算符,是正则表达式(regular expression)的缩写,正则表达式在搜索字符串时非常强大,下面是关于它的应用
1.查找名字中包含field的顾客
select *
from customers
where last_name like '%field%'

运用REGEXP运算符,可以这样写,同样可以得出数据
select *
from customers
where last_name regexp 'field'

2.查找姓氏以Brush开头的顾客
^表示查找的字符串必须以什么开头
select *
from customers
where last_name regexp '^brush'

3.查找姓氏以field结尾的顾客
$表示查找的字符串必须以什么结尾
select *
from customers
where last_name regexp 'field$'

3.查找姓氏包含field或者mac的顾客
|符号表示多个搜寻模式
select *
from customers
where last_name regexp 'brush|mac'

4.查找以brush开头,或者包含mac,或者包含rose的顾客
select *
from customers
where last_name regexp '^brush|mac|rose'

5.查找姓氏包含e,且前面要有g或i或m
select *
from customers
where last_name regexp '[gim]e'

6.查找姓氏包含e,且后面要有a但h中的一个字母
select *
from customers
where last_name regexp 'e[a-h]'

总结:
^表示字符串开头
¥表示字符串结尾
|表示逻辑上的or,可以给出多个搜索模式
[]表示任意在括号里列举的单字符
[-]表示任意在括号内范围内的单字符
练习
1.获取名字是Elka或者Ambur的顾客
select *
from customers
where first_name regexp 'elka|ambur'

2.返回姓氏以ey或者on结尾的顾客
select *
from customers
where last_name regexp 'ey$|on$'

3.获取姓氏以my打头,或者包含se的顾客
select *
from customers
where last_name regexp '^my|se'

4.返回顾客,姓氏包含b,然后是r或者u
select *
from customers
where last_name regexp 'b[ru]'

先自我介绍一下,小编13年上师交大毕业,曾经在小公司待过,去过华为OPPO等大厂,18年进入阿里,直到现在。深知大多数初中级java工程师,想要升技能,往往是需要自己摸索成长或是报班学习,但对于培训机构动则近万元的学费,着实压力不小。自己不成体系的自学效率很低又漫长,而且容易碰到天花板技术停止不前。因此我收集了一份《java开发全套学习资料》送给大家,初衷也很简单,就是希望帮助到想自学又不知道该从何学起的朋友,同时减轻大家的负担。添加下方名片,即可获取全套学习资料哦
边栏推荐
猜你喜欢

2022-07-23 第六小组 瞒春 学习笔记

虚拟现实处理器(SXR2130P)ISO7640FMDW(数字隔离器)说明

2022-07-19 第五小组 瞒春 学习笔记

软件代码签名证书怎么申请

Getting Started with MySQL Syntax

2022 VMware下载安装教程

【Leetcode字符串--字符串变换/进制的转换】HJ1.字符串最后一个单词的长度 HJ2.计算某字符出现次数 HJ30.字符串合并处理

已解决ModuleNotFoundError: No module named‘ pip‘(重新安装pip的两种方式)

2022-07-26 第六小组 瞒春 学习笔记

【 Leetcode string, the string transform/hexadecimal conversion 】 HJ1. The length of the string last word HJ2. Calculation of a certain number of characters appear HJ30. String merging processing
随机推荐
vite.config.ts introduces the `path` module Note!
es6 循环,并终止循环
2022-07-27 第六小组 瞒春 学习笔记
PAT tree DP (memory search) class a, 1079, 1090, 1106
IPtables and binlog
散列表简述
MySQL查询
如何用JDBC操作Mysql
【无标题】
A status code, and access baidu process
遍历堆 PAT甲级 1155 堆路径
"No title"
【无标题】
《数字经济全景白皮书》银行业智能风控科技应用专题分析 发布
PAT Class A 1019 Common Palindrome Numbers
软件代码签名证书怎么申请
2022-02-14 第五小组 瞒春 学习笔记
NXP i.MX 8M Mini工业核心板B2B版本,4核ARM [email protected]设计
MySQL 高级(进阶) SQL 语句 (一)
codeforces k-Tree (dp still won't work)