溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

怎么在PostGreSql中判斷字符串中是否有中文

發(fā)布時間:2021-02-03 12:39:57 來源:億速云 閱讀:1081 作者:Leah 欄目:開發(fā)技術

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

實例

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)

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

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng)、轉載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權內容。

AI