這篇文章主要介紹“MySQL REGEXP怎么使用”,在日常操作中,相信很多人在MySQL REGEXP怎么使用問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對(duì)大家解答”MySQL REGEXP怎么使用”的疑惑有所幫助!接下來,請(qǐng)跟著小編一起來學(xué)習(xí)吧!
清河網(wǎng)站制作公司哪家好,找創(chuàng)新互聯(lián)建站!從網(wǎng)頁設(shè)計(jì)、網(wǎng)站建設(shè)、微信開發(fā)、APP開發(fā)、成都響應(yīng)式網(wǎng)站建設(shè)公司等網(wǎng)站項(xiàng)目制作,到程序開發(fā),運(yùn)營維護(hù)。創(chuàng)新互聯(lián)建站成立于2013年到現(xiàn)在10年的時(shí)間,我們擁有了豐富的建站經(jīng)驗(yàn)和運(yùn)維經(jīng)驗(yàn),來保證我們的工作的順利進(jìn)行。專注于網(wǎng)站建設(shè)就選創(chuàng)新互聯(lián)建站。
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)算,這主要通過正則表達(dá)式來實(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ù)庫名
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)注創(chuàng)新互聯(lián)網(wǎng)站,小編會(huì)繼續(xù)努力為大家?guī)砀鄬?shí)用的文章!