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?
----------
 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)

可以看出,数组的包含操作符判断的时候不管顺序、重复,只要包含了就返回true,在真正使用的时候注意。

文章来源:脚本之家

来源地址:https://www.jb51.net/article/205193.htm

免责申明:
1. 本站所有下载资源均不包含技术支持和安装服务!需要讨论请进群!
2. 分享目的仅供大家学习和交流,请不要用于商业用途!
3. 如果你也有好源码或者教程,可以到审核区发布,分享有KR奖励和额外收入!
4. 如有链接无法下载、失效或广告,请联系管理员处理!
5. 本站无法保证资源或破解时效性,如某些授权码过期等问题,恕不在修复范围内。
6. 本站资源售价只是赞助,收取费用仅维持本站的日常运营所需!故不接受任何形式的退款,如确认资源确有问题的,会补给相应KR以供再次购买。
7. 53Kr源码暂未发现后门代码,但无法保证100%安全,推荐检测方法:上传到 https://www.virustotal.com/在线查看是否有恶意代码以及其他有后门嫌疑的代码。
8. 在本站下载的源码我还是不建议正式使用,有特别喜欢的可以去程序官方购买。
53kr资源站仅提供学习的平台,所有资料均来自于网络,版权归原创者所有!本站不提供任何保证,并不承担任何法律责任,如果对您的版权或者利益造成损害,请提供相应的资质证明,我们将于3个工作日内予以删除。
53kr资源分享 » PostGreSql 判断字符串中是否有中文的案例

发表回复