create or replace function f_get_value(keystr varchar2,source_str varchar2) return varchar2
is
v_idx number := 0;
v_p_idx number := 0;
v_v_idx number := 0;
v_key_num number := 0;
v_len number := 0;
v_result varchar2(64);
begin 
  v_key_num := regexp_count(source_str,'{\w+}');
  v_len := length(source_str);
  v_v_idx := instr(source_str,keystr);
  for i in 1..v_key_num loop
    v_idx := instr(source_str,'{',1,i);
    if v_idx > v_v_idx then
      v_p_idx := v_idx;
      exit;
    end if;
  end loop;
  if v_p_idx = 0 and v_v_idx != 0 then
    v_p_idx := v_len+1;
  end if;
  v_result := substr(source_str,v_v_idx+length(keystr),v_p_idx-v_v_idx-length(keystr));
  return v_result;
exception
  when others then
    v_result := 'ERROR';
    return v_result;
end f_get_value;

解决方案 »

  1.   


    create or replace function getValue(str_i_val in varchar2, str_i_key varchar2) return varchar2 as
    begin
        if instr(str_i_val||'{', str_i_key) = 0 then
          return 'NOT FOUND';
        else
          return substr(str_i_val||'{', instr(str_i_val||'{', str_i_key)+length(str_i_key),
          instr(str_i_val||'{', '{', instr(str_i_val||'{', str_i_key)+length(str_i_key)) - (instr(str_i_val||'{', str_i_key)+length(str_i_key)));
        end if;
    end;第一个参数传入你的这个参数{name}test{worker_id}S0888{EMAIL}[email protected]   
    第二个参数传入{name}或者{EMAIL}
      

  2.   

    返回今天是星期幾--(若當天是星期五,則1.1返回星期五--1.2返回 Friday)(用Oracle完成)  这个具体做法不这么怎么做啊