国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 數據庫 > MySQL > 正文

mysql中如何使用正則表達式查詢

2020-01-18 23:15:44
字體:
來源:轉載
供稿:網友
基本形式

屬性名 regexp ‘匹配方式'

正則表達式的模式字符

^ 匹配字符開始的部分

eg1: 從info表name字段中查詢以L開頭的記錄

select * from info where name regexp '^L';

eg2: 從info表name字段中查詢以aaa開頭的記錄

select * from info where name regexp '^aaa';

$ 匹配字符結束的部分

eg1: 從info表name字段中查詢以c結尾的記錄

select * from info where name regexp 'c$';

eg2: 從info表name字段中查詢以aaa結尾的記錄

select * from info where name regexp 'aaa$';

. 匹配字符串中的任意一個字符,包括回車和換行

eg1: 從info表name字段中查詢以L開頭y結尾中間有兩個任意字符的記錄

select * from info where name regexp '^L..y$';

[字符集合]匹配字符集合中的任意字符

eg1: 從info表name字段中查詢包含c、e、o三個字母中任意一個的記錄

select * from info where name regexp '[ceo]';

eg2: 從info表name字段中查詢包含數字的記錄

select * from info where name regexp '[0-9]';

eg3: 從info表name字段中查詢包含數字或a、b、c三個字母中任意一個的記錄

select * from info where name regexp '[0-9a-c]';

[^字符集合]匹配除了字符集合外的任意字符

eg1: 從info表name字段中查詢包含a-w字母和數字以外字符的記錄

select * from info where name regexp '[^a-w0-9]';

s1|s2|s3 匹配s1s2s3中的任意一個

eg1: 從info表name字段中查詢包含'ic'的記錄

select * from info where name regexp 'ic';

eg2: 從info表name字段中查詢包含ic、uc、ab三個字符串中任意一個的記錄

select * from info where name regexp 'ic|uc|ab';

* 代表多個該字符前的字符,包括0個或1個

eg1: 從info表name字段中查詢c之前出現過a的記錄

select * from info where name regexp 'a*c';

+ 代表多個該字符前的字符,包括1個

eg1: 從info表name字段中查詢c之前出現過a的記錄

select * from info where name regexp 'a+c';(注意比較結果!)

字符串{N} 字符串出現N次

eg1: 從info表name字段中查詢出現過a3次的記錄

select * from info where name regexp 'a{3}';

字符串{M,N}字符串最少出現M次,最多出現N次

eg1: 從info表name字段中查詢ab出現最少1次最多3次的記錄

select * from info where name regexp 'ab{1,3}';

MYSQL中自帶通配符(LIKE關鍵詞)

%可以表示任意長度的字符(包括0)

-可以表示單個字符
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 岢岚县| 宣化县| 营山县| 临漳县| 湘潭市| 鹤壁市| 嘉禾县| 大足县| 格尔木市| 交城县| 马尔康县| 政和县| 杭锦旗| 太保市| 洛川县| 克什克腾旗| 长春市| 桂阳县| 醴陵市| 高要市| 南溪县| 汝阳县| 横峰县| 石城县| 伊金霍洛旗| 自治县| 永胜县| 通榆县| 亚东县| 旌德县| 皮山县| 曲水县| 镶黄旗| 恩施市| 闽侯县| 上饶市| 永和县| 武城县| 顺昌县| 库伦旗| 墨脱县|