PostGreSql 判斷字符串中是否有中文的案例
我就廢話不多說了,大家還是直接看代碼吧~
實(shí)例
imos=# select 'hello' ~ '[\u2e80-\ua4cf]|[\uf900-\ufaff]|[\ufe30-\ufe4f]'; ?column? ---------- f (1 row) imos=# imos=# select 'hello中國' ~ '[\u2e80-\ua4cf]|[\uf900-\ufaff]|[\ufe30-\ufe4f]'; ?column? ---------- t (1 row)
補(bǔ)充:PostgreSQL 判斷字符串包含的幾種方法
判斷字符串包含的幾種方法:
1. position(substring in string):
postgres=# select position('aa' in 'abcd');
position
----------
0
(1 row)
postgres=# select position('ab' in 'abcd');
position
----------
1
(1 row)
postgres=# select position('ab' in 'abcdab');
position
----------
1
(1 row)
可以看出,如果包含目標(biāo)字符串,會(huì)返回目標(biāo)字符串笫一次出現(xiàn)的位置,可以根據(jù)返回值是否大于0來判斷是否包含目標(biāo)字符串。
2. strpos(string, substring):
該函數(shù)的作用是聲明子串的位置。
postgres=# select strpos('abcd','aa');
strpos
--------
0
(1 row)
postgres=# select strpos('abcd','ab');
strpos
--------
1
(1 row)
postgres=# select strpos('abcdab','ab');
strpos
--------
1
(1 row)
作用與position函數(shù)一致。
3. 使用正則表達(dá)式:
postgres=# select 'abcd' ~ 'aa'; ?column? ---------- f (1 row) postgres=# select 'abcd' ~ 'ab'; ?column? ---------- t (1 row) postgres=# select 'abcdab' ~ 'ab'; ?column? ---------- t (1 row)
4. 使用數(shù)組的@>操作符(不能準(zhǔn)確判斷是否包含):
postgres=# select regexp_split_to_array('abcd','') @> array['b','e'];
?column?
----------
f
(1 row)
postgres=# select regexp_split_to_array('abcd','') @> array['a','b'];
?column?
----------
t
(1 row)
注意下面這些例子:
postgres=# select regexp_split_to_array('abcd','') @> array['a','a'];
?column?
----------
t
(1 row)
postgres=# select regexp_split_to_array('abcd','') @> array['a','c'];
?column?
----------
t
(1 row)
postgres=# select regexp_split_to_array('abcd','') @> array['a','c','a','c'];
?column?
----------
t
(1 row)
可以看出,數(shù)組的包含操作符判斷的時(shí)候不管順序、重復(fù),只要包含了就返回true,在真正使用的時(shí)候注意。
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教。
- PostgreSQL的中文拼音排序案例
- 自定義函數(shù)實(shí)現(xiàn)單詞排序并運(yùn)用于PostgreSQL(實(shí)現(xiàn)代碼)
- PostgreSQL將數(shù)據(jù)加載到buffer cache中操作方法
- 在PostgreSQL中使用ltree處理層次結(jié)構(gòu)數(shù)據(jù)的方法
- postgresql 中的時(shí)間處理小技巧(推薦)
- Postgresql限制用戶登錄錯(cuò)誤次數(shù)的實(shí)例代碼
- PostgreSQL用戶登錄失敗自動(dòng)鎖定的處理方案
- postgresql影子用戶實(shí)踐場(chǎng)景分析
- 如何使用PostgreSQL進(jìn)行中文全文檢索
相關(guān)文章
psql除法保留小數(shù),實(shí)現(xiàn)向上取整和向下取整操作
這篇文章主要介紹了psql除法保留小數(shù),實(shí)現(xiàn)向上取整和向下取整操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2021-01-01
postgresql數(shù)據(jù)合并,多條數(shù)據(jù)合并成1條的操作
這篇文章主要介紹了postgresql數(shù)據(jù)合并,多條數(shù)據(jù)合并成1條的操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2021-02-02
PostgreSQL數(shù)據(jù)庫事務(wù)實(shí)現(xiàn)方法分析
這篇文章主要介紹了PostgreSQL數(shù)據(jù)庫事務(wù)實(shí)現(xiàn)方法,簡(jiǎn)單講述了事務(wù)的概念、功能,并結(jié)合實(shí)例形式分析了PostgreSQL數(shù)據(jù)庫事務(wù)的定義方法及相關(guān)注意事項(xiàng),需要的朋友可以參考下2018-08-08
postgresql數(shù)據(jù)庫連接數(shù)和狀態(tài)查詢操作
這篇文章主要介紹了postgresql數(shù)據(jù)庫連接數(shù)和狀態(tài)查詢操作,具有很好的參考價(jià)值,對(duì)大家有所幫助。一起跟隨小編過來看看吧2021-02-02
postgresql 存儲(chǔ)函數(shù)調(diào)用變量的3種方法小結(jié)
這篇文章主要介紹了postgresql 存儲(chǔ)函數(shù)調(diào)用變量的3種方法小結(jié),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2021-01-01
windows PostgreSQL 9.1 安裝詳細(xì)步驟
這篇文章主要介紹了windows PostgreSQL 9.1 安裝詳細(xì)步驟,需要的朋友可以參考下2016-11-11
DBeaver中PostgreSQL數(shù)據(jù)庫顯示不全的解決方法
最近,在DBeaver中連接了本地的PostgreSQL數(shù)據(jù)庫,但是連接后打開這個(gè)數(shù)據(jù)庫時(shí)發(fā)現(xiàn),數(shù)據(jù)庫顯示不全,所以本文給大家介紹了DBeaver中PostgreSQL數(shù)據(jù)庫顯示不全的解決方法,需要的朋友可以參考下2024-11-11

