創(chuàng)新互聯(lián)www.cdcxhl.cn八線動態(tài)BGP香港云服務器提供商,新人活動買多久送多久,劃算不套路!
這篇文章將為大家詳細講解有關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)的位置,可以根據返回值是否大于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)
關于postgresql判斷有沒有存在某個字符的方法就分享到這里了,希望以上內容可以對大家有一定的幫助,可以學到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。