共計(jì) 4591 個(gè)字符,預(yù)計(jì)需要花費(fèi) 12 分鐘才能閱讀完成。
這篇文章主要介紹“MySQL REGEXP 怎么使用”,在日常操作中,相信很多人在 MySQL REGEXP 怎么使用問(wèn)題上存在疑惑,丸趣 TV 小編查閱了各式資料,整理出簡(jiǎn)單好用的操作方法,希望對(duì)大家解答”MySQL REGEXP 怎么使用”的疑惑有所幫助!接下來(lái),請(qǐng)跟著丸趣 TV 小編一起來(lái)學(xué)習(xí)吧!
1. 關(guān)于 NULL
普通的比較運(yùn)算符用于 NULL,返回的結(jié)果都是 NULL。
mysql select 0 = null, 1 null, 2 null, 3 null, 4 = null, 5 = null;
+———-+———–+———-+———-+———–+———–+
| 0 = null | 1 null | 2 null | 3 null | 4 = null | 5 = null |
+———-+———–+———-+———-+———–+———–+
| NULL | NULL | NULL | NULL | NULL | NULL |
+———-+———–+———-+———-+———–+———–+
1 row in set (0.00 sec)
[@more@] 要判斷一個(gè)值是否為 NULL,應(yīng)該使用 IS NULL、IS NOT NULL 或 =(NULL 安全地等于)等運(yùn)算符。
mysql select 0 is null, null is null;
+———–+————–+
| 0 is null | null is null |
+———–+————–+
| 0 | 1 |
+———–+————–+
1 row in set (0.00 sec)
mysql select 0 is not null, null is not null;
+—————+——————+
| 0 is not null | null is not null |
+—————+——————+
| 1 | 0 |
+—————+——————+
1 row in set (0.00 sec)
mysql select 0 = null, null = null;
+————+—————+
| 0 = null | null = null |
+————+—————+
| 0 | 1 |
+————+—————+
1 row in set (0.00 sec)
在 MySQL 中,NULL 不同于空值。
mysql select IS NULL;
+————+
| IS NULL |
+————+
| 0 |
+————+
1 row in set (0.00 sec)
2.REGEXP
REGEXP 運(yùn)算符可以執(zhí)行較復(fù)雜的字符串比較運(yùn)算,這主要通過(guò)正則表達(dá)式來(lái)實(shí)現(xiàn)。正則表達(dá)式由標(biāo)準(zhǔn)字符和專門定義匹配模式的元字符混合組成,下表列出了正則表達(dá)式中經(jīng)常使用的元字符:
元字符 作用
+ 匹配 1 個(gè)或更多個(gè)前面字符的值
* 匹配 0 個(gè)或更多個(gè)前面字符的值
? 匹配 0 個(gè)或 1 前面字符的值
. 匹配任意字符
^ 匹配字符串的開始部分
$ 匹配字符串的末尾部分
s 匹配單個(gè)空白空間字符,包括制表符合換行符
S 匹配空白空間字符以外的一切字符
d 匹配 0 到 9 之間的數(shù)字
w 匹配字母、數(shù)字和下滑線字符
W 匹配用 w 不能匹配的任意字符
mysql select google regexp go+ogle , google regexp go*ogle , google reg
exp go?ogle
+—————————+—————————+———————–
—-+
| google regexp go+ogle | google regexp go*ogle | google regexp go?og
le |
+—————————+—————————+———————–
—-+
| 1 | 1 |
1 |
+—————————+—————————+———————–
—-+
1 row in set (0.00 sec)
mysql select google regexp go+gle , google regexp go*gle , google regex
p go?gle
+————————–+————————–+————————-
-+
| google regexp go+gle | google regexp go*gle | google regexp go?gle
|
+————————–+————————–+————————-
-+
| 1 | 1 | 0
|
+————————–+————————–+————————-
-+
1 row in set (0.00 sec)
mysql select google regexp gooo+gle , google regexp gooo*gle , google r
egexp gooo?gle
+—————————-+—————————-+———————
——-+
| google regexp gooo+gle | google regexp gooo*gle | google regexp goo
o?gle |
+—————————-+—————————-+———————
——-+
| 0 | 1 |
1 |
+—————————-+—————————-+———————
——-+
1 row in set (0.00 sec)
mysql select google regexp ^goo , google regexp goo$
+————————+————————+
| google regexp ^goo | google regexp goo$ |
+————————+————————+
| 1 | 0 |
+————————+————————+
1 row in set (0.00 sec)
mysql select google regexp ^gle , google regexp gle$
+————————+————————+
| google regexp ^gle | google regexp gle$ |
+————————+————————+
| 0 | 1 |
+————————+————————+
1 row in set (0.00 sec)
mysql select fifi regexp ^fi , fifi regexp fi$ , fifi regexp ^fi$ , f
ifi regexp ^fifi$
+———————+———————+———————-+————
————+
| fifi regexp ^fi | fifi regexp fi$ | fifi regexp ^fi$ | fifi rege
xp ^fifi$ |
+———————+———————+———————-+————
————+
| 1 | 1 | 0 |
1 |
+———————+———————+———————-+————
————+
1 row in set (0.00 sec)
3. 系統(tǒng)信息函數(shù)
下面列舉一些常用的系統(tǒng)信息函數(shù):
user() 或 system_user() 返回當(dāng)前登陸用戶名
connection_id() 返回當(dāng)前用戶的連接 ID
database() 返回當(dāng)前數(shù)據(jù)庫(kù)名
version() 返回 MySQL 服務(wù)器的版本
mysql select user(), connection_id(), database(), version();
+—————-+—————–+————+——————+
| user() | connection_id() | database() | version() |
+—————-+—————–+————+——————+
| root@localhost | 2 | ggyy | 5.1.34-community |
+—————-+—————–+————+——————+
1 row in set (0.40 sec)
undefinedundefinedundefinedundefinedundefined
到此,關(guān)于“MySQL REGEXP 怎么使用”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實(shí)踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識(shí),請(qǐng)繼續(xù)關(guān)注丸趣 TV 網(wǎng)站,丸趣 TV 小編會(huì)繼續(xù)努力為大家?guī)?lái)更多實(shí)用的文章!