怎么在PostGreSql中判斷字符串中是否有中文-創(chuàng)新互聯(lián)

今天就跟大家聊聊有關怎么在PostGreSql中判斷字符串中是否有中文,可能很多人都不太了解,為了讓大家更加了解,小編給大家總結(jié)了以下內(nèi)容,希望大家根據(jù)這篇文章可以有所收獲。

創(chuàng)新互聯(lián)建站成立與2013年,公司以成都網(wǎng)站制作、成都網(wǎng)站建設、系統(tǒng)開發(fā)、網(wǎng)絡推廣、文化傳媒、企業(yè)宣傳、平面廣告設計等為主要業(yè)務,適用行業(yè)近百種。服務企業(yè)客戶成百上千家,涉及國內(nèi)多個省份客戶。擁有多年網(wǎng)站建設開發(fā)經(jīng)驗。為企業(yè)提供專業(yè)的網(wǎng)站建設、創(chuàng)意設計、宣傳推廣等服務。 通過專業(yè)的設計、獨特的風格,為不同客戶提供各種風格的特色服務。

實例


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)

補充: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)

可以看出,如果包含目標字符串,會返回目標字符串笫一次出現(xiàn)的位置,可以根據(jù)返回值是否大于0來判斷是否包含目標字符串。

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. 使用正則表達式:

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ù)組的@>操作符(不能準確判斷是否包含):

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)

看完上述內(nèi)容,你們對怎么在PostGreSql中判斷字符串中是否有中文有進一步的了解嗎?如果還想了解更多知識或者相關內(nèi)容,請關注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝大家的支持。

網(wǎng)站名稱:怎么在PostGreSql中判斷字符串中是否有中文-創(chuàng)新互聯(lián)
網(wǎng)站地址:http://www.muchs.cn/article10/dpcpdo.html

成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站維護、靜態(tài)網(wǎng)站、微信公眾號、標簽優(yōu)化、網(wǎng)站策劃、軟件開發(fā)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

綿陽服務器托管