这篇文章主要介绍了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 判断字符串中是否有中文的案例】补充: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
申请创业报道,分享创业好点子 。,共同探讨创业新机遇!
- 如何看一块石头里面有没有玉 怎么判断是玉还是石头
- 扁平疣这个词第三个字怎么读 小疙瘩怎么判断是不是疣
- 扁平疣快好了是什么样子啊 如何判断扁平疣在好转
- 怎么判断是不是得了前列腺炎 前列腺炎症状会消失吗
- 膀胱结石到底该如何判断呢 尿结石分几种类型
- 如何判断自己是否感染了HIV 高危第二天马上有症状
- 能排除不是新型肺炎吗 新型肺炎症状怎么判断
- 尖锐湿疣和珍珠疹有什么区别 怎么判断是不是珍珠疹
- 胰岛素有哪些副作用 怎样判断胰岛功能完全丧失
- 宝宝积食会出现5种表现 怎么判断宝宝是否积食了
特别声明:本站内容均来自网友提供或互联网,仅供参考,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
