PostgreSQL中如何得到一个随机的字符
1个回答
展开全部
可以用函数实现, 如下:
create or replace function get_txt_count(p_source_txt character varying, p_count_txt character varying)returns integeras $get_txt_count$declarev_idx integer := 1;v_cnt integer := 0;v_source_txt character varying(2000) := p_source_txt;v_len integer := length(p_count_txt);begin while v_idx > 0 loop v_idx := position(p_count_txt in v_source_txt); if v_idx > 0 then v_cnt := v_cnt + 1; v_source_txt := right(v_source_txt, length(v_source_txt) - v_idx - v_len + 1); end if; end loop; return v_cnt;end;$get_txt_count$ language plpgsql;
调用:
select get_txt_count('a.b.c.d.e', '.');
create or replace function get_txt_count(p_source_txt character varying, p_count_txt character varying)returns integeras $get_txt_count$declarev_idx integer := 1;v_cnt integer := 0;v_source_txt character varying(2000) := p_source_txt;v_len integer := length(p_count_txt);begin while v_idx > 0 loop v_idx := position(p_count_txt in v_source_txt); if v_idx > 0 then v_cnt := v_cnt + 1; v_source_txt := right(v_source_txt, length(v_source_txt) - v_idx - v_len + 1); end if; end loop; return v_cnt;end;$get_txt_count$ language plpgsql;
调用:
select get_txt_count('a.b.c.d.e', '.');
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询