PostGreSql 判断字符串中是否有中文的例子

这篇文章主要介绍了PostGreSql 判断字符串中是否有中文的案例,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧。
 
我就废话不多说了,大家还是直接看代码吧~
 
实例
 
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 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)
 
可以看出,如果包含目标字符串,会返回目标字符串笫一次出现的位置,可以根据返回值是否大于0来判断是否包含目标字符串。
 
2. strpos(string, substring):
 
该函数的作用是声明子串的位置。
 
postgres=# select 'abcd' ~ 'aa';
 ?column?
———-
 f
(1 row)
postgres=# select 'abcd' ~ 'ab';
 ?column?
———-
 t
(1 row)
postgres=# select 'abcdab' ~ 'ab';
 ?column?
———-
 t
(1 row)
 
作用与position函数一致。
 
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. 使用数组的@>操作符(不能准确判断是否包含):
 
postgres=# select regexp_split_to_array('abcd','') @> array['b','e'];
 ?column?
———-
【声明】:芜湖站长网内容转载自互联网,其相关言论仅代表作者个人观点绝非权威,不代表本站立场。如您发现内容存在版权问题,请提交相关链接至邮箱:bqsm@foxmail.com,我们将及时予以处理。

相关文章