遍歷字符串,並將大寫字母前加_前綴

create or replace function func_upper(v_str in varchar2) return varchar2 as
  v_char varchar2(200);
begin
  v_char := '';
  for i in 1 .. length(v_str) loop
    --dbms_output.put_line(i);
    if regexp_instr(substr(v_str, i, 1), '[A-Z]') = 0 then
      v_char := v_char || substr(v_str, i, 1);
    elsif regexp_instr(substr(v_str, i, 1), '[A-Z]') = 1 then
      v_char := v_char || '_' || substr(v_str, i, 1);
    end if;
    --dbms_output.put_line(regexp_instr(substr(v_str,i,1),'[A-Z]'));
    --dbms_output.put_line(replace(v_str,substr(v_str,i,1),'_'||substr(v_str,i,1)));
  end loop;
  return v_char;
end;
複製代碼

image-20210623094933238

select replace(to_char(wm_concat(case
                                   when REGEXP_INSTR(data1, '[A-Z]') = 1 then
                                    '_' || data1
                                   else
                                    data1
                                 end)),
               ',',
               '')
  from (select substr('aBBbcDeF', level, 1) as data1
          from dual
        connect by level <= length('aBBcDeF'))
複製代碼

image-20210623094850900

相關文章
相關標籤/搜索