20. orcle中统计一个字符串中某个字符的长度

时间:2023-03-09 17:04:45
20. orcle中统计一个字符串中某个字符的长度

例子1:统计一个字符串中“,”的个数:

select lengthb(regexp_replace('[a,b,c,d,e,f]','[^,]',null))  as res from dual;

例子2:查询lborganization表中字段fdncode包含1个"."号的所有记录:
select * from lborganization a where lengthb(regexp_replace('['||a.fdncode||']','[^.]',null)) =1;

例子3:把lborganization表中字段fdncode包含4个"."号的所有记录中的grade改为4:

update lborganization a set a.grade = 4 where lengthb(regexp_replace('['||a.fdncode||']','[^.]',null)) =4;