1 Star 0 Fork 1

huchaochao/mysql_bizhibihui

forked from dongpo1000/mysql_study 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
第09章 使用正则表达式进行搜索.sql 1.38 KB
一键复制 编辑 原始数据 按行查看 历史
dongpo1000 提交于 2020-12-30 13:57 . 修改文件名以自动排序
# 9 使用正则表达式进行搜索
USE mysql_bizhibihui;
# 基本字符匹配
SELECT prod_name
FROM products
WHERE prod_name REGEXP '1000'
ORDER BY prod_name;
SELECT prod_name
FROM products
WHERE prod_name REGEXP '.000'
ORDER BY prod_name;
# LIKE 的区别
SELECT prod_name
FROM products
WHERE prod_name LIKE '1000'
ORDER BY prod_name;
# 进行 OR 匹配
SELECT prod_name
FROM products
WHERE prod_name REGEXP '1000|2000'
ORDER BY prod_name;
# 匹配几个字符之一
SELECT prod_name
FROM products
WHERE prod_name REGEXP '[123] Ton'
ORDER BY prod_name;
SELECT prod_name
FROM products
WHERE prod_name REGEXP '1|2|3| Ton'
ORDER BY prod_name;
# 匹配范围
SELECT prod_name
FROM products
WHERE prod_name REGEXP '[1-5] Ton'
ORDER BY prod_name;
# 匹配特殊字符
SELECT vend_name
FROM vendors
WHERE vend_name REGEXP '.'
ORDER BY vend_name;
SELECT vend_name
FROM vendors
WHERE vend_name REGEXP '\\.'
ORDER BY vend_name;
# 匹配多个实例
SELECT prod_name
FROM products
WHERE prod_name REGEXP '\\([0-9] sticks?\\)'
ORDER BY prod_name;
SELECT prod_name
FROM products
WHERE prod_name REGEXP '[[:digit:]]{4}'
ORDER BY prod_name;
SELECT prod_name
FROM products
WHERE prod_name REGEXP '[0-9][0-9][0-9][0-9]'
ORDER BY prod_name;
# 定位符
SELECT prod_name
FROM products
WHERE prod_name REGEXP '^[0-9\\.]'
ORDER BY prod_name;
# 正则表达式测试
SELECT 'hello' REGEXP '[0-9]';
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/hcc817/mysql_bizhibihui.git
git@gitee.com:hcc817/mysql_bizhibihui.git
hcc817
mysql_bizhibihui
mysql_bizhibihui
master

搜索帮助