postgres:

SELECT array_length(regexp_split_to_array(gs.gss,'ss'),1)-1 as num from table gs

若有特殊字符,用\转译

如下,查询 /* 和 */出现的次数不相等的记录:(*是特殊字符)


SELECT * from (
SELECT array_length(regexp_split_to_array(gs.gss,'/\*'),1)-1 as le,  array_length(regexp_split_to_array(gs.gss,'\*/'),1)-1 as rrrr,  gs.id  from table gs
) a where a.le != a.rrrr


 

mysql:

SELECT array_length(regexp_split_to_array(gs.gs,'/\*'),1)-1 as le

SELECT * from (
 SELECT LENGTH(gs.gs)-LENGTH(REPLACE(gs.gs,'/\*','')) as le ,LENGTH(gs.gs)-LENGTH(REPLACE(gs.gs,'\*/','')) as rrrr  from t_jxsjgsb gs
) a where a.le != a.rrrr

Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐