PostGreSql确定字符串中是否有中文
  • 作者:admin
  • 发表时间:2021-05-06 07:51
  • 来源:未知

本文主要介绍PostGreSql判断字符串中是否有中文的案例,有很好的参考价值,希望对大家有所帮助。来和边肖一起看看。

废话不多说,直接看代码就好了~

例子

imos=# select ' hello ' ~ '[\ u2e 80-\ ua4cf]|[\ uf 900-\ ufaff]|[\ ufe 30-\ ufe 4f]';

?专栏?

-

f

(1行)

imos=#

imos=# select ' hello China ' ~ '[\ u2e 80-\ ua4cf]|[\ uf 900-\ ufaff]|[\ ufe 30-\ ufe 4f]';

?专栏?

-

t

(1行)

补充:PostgreSQL判断字符串包含的几种方法

判断字符串包含的几种方法;

1.位置(字符串中的子字符串):

postgres=# select strpos('abcd ',' aa ');

查找字符串首次出现的位置

-

0

(1行)

postgres=# select strpos('abcd ',' ab ');

查找字符串首次出现的位置

-

一个

(1行)

postgres=# select strpos('abcdab ',' ab ');

查找字符串首次出现的位置

-

一个

(1行)

可以看出,如果包含目标字符串,将返回目标字符串出现一次的位置,根据返回值是否大于0可以判断是否包含目标字符串。

2.strpos(字符串,子字符串):

该函数声明子字符串的位置。

postgres=# select ' abcd ' ~ ' aa

?专栏?

-

f

(1行)

Postgres=# select 'abcd' ~ 'ab '唐山网络公司;

?专栏?

-

t

(1行)

postgres=# select ' abcdab ' ~ ' ab

?专栏?

-

t

(1行)

动作与位置功能一致。

3.使用正则表达式:

postgres=# select ' abcd ' ~ ' aa

?专栏?

-

f

(1行)

postgres=# select ' abcd ' ~ ' ab

?专栏?

-

t

(1行)

postgres=# select ' abcdab ' ~ ' ab

?专栏?

-

t

(1行)

4.使用数组的@运算符(无法准确判断是否包含):

postgres=# select regexp _ split _ to _ array(' ABCD ',' ')@ array['b ',' e '];

?专栏?

-

f

(1行)

postgres=# select regexp _ split _ to _ array(' ABCD ',' ')@ array['a ',' b '];

?专栏?

-

t

(1行)

请注意以下示例:

postgres=# select regexp _ split _ to _ array(' ABCD ',' ')@ array['a ',' a '];

?专栏?

-

t

(1行)

postgres=# select regexp _ split _ to _ array(' ABCD ',' ')@ array['a ',' c '];