/*-------------------------------------------------------------------------
  || 函数名称 :转换成拼音码或者五笔码
  || 功能描述 :将传入的字符串转换成相应的拼音码或者五笔码
  ||
  || 参数描述 :参数标识      输入/输出       类型          名称
  ||            -------------------------------------------------------------
  ||            v_string       输入           varchar2      需要转换的字符串
  ||            v_type         输入           number        转换类型-0 转换成五笔码,1 (或其他)转换成拼音码,
  || 返回:     字符型   转换后的查询码,如果出错误返回''
  ||-------------------------------------------------------------------------
  || 作    者 :       
  || 备注     :
  || 更新日期 :
  ||-------------------------------------------------------------------------*/
  create or replace function fun_get_query_code(v_string    In VARCHAR2,
                                                v_spellFlag In number)
  return VARCHAR2 is  I            NUMBER(10);
  li_count     NUMBER(10);
  ls_returnstr VARCHAR2(50);
  ls_ch        VARCHAR2(20);
  ls_temp      VARCHAR2(20);
begin  IF v_string is null then
  
    return v_string;
  
  End if;
  IF v_string is not null then
  
    ls_returnstr := '';
    I            := '1';
    li_count     := length(substr(v_string, 1, 30));
  
    WHILE I <= li_count LOOP
    
      ls_ch := substr(v_string, I, 1);
      
      --英文处理
      If ASCII(ls_ch) < 128 
         
         --中文处理,这里写死了 我想不需要写死,怎么去修改?比如中文的‘(’,'$'等这里没法处理。
 
         or ASCII(ls_ch) = '41896' or
         ASCII(ls_ch) = '41897' or ASCII(ls_ch) = '44646' then
        ls_returnStr := ls_returnStr || upper(ls_ch);
      else if ASCII(ls_ch) > 128 then
           v_temp := v_temp || substr(SourceSql, i + 1, 1);
        
      else
        --汉字处理,如果B_BASIC_SPELLBASE字典表里面查询结果无返回值,我想原样输出这个ls_ch,怎么解决
        IF v_spellFlag = 0 then
       
          
          select WB_CODE
            into ls_temp
            from B_BASIC_SPELLBASE
           where NAME = ls_ch;
          if 
        else
        --汉字处理,如果B_BASIC_SPELLBASE字典表里面查询结果无返回值,我想原样输出这个ls_ch,怎么解决
          select
           SPELL_CODE
            into ls_temp
            from B_BASIC_SPELLBASE
           where NAME = ls_ch;
        
        End if;
      
      End if;
      ls_returnstr := ls_returnStr || '' || ls_temp;
      I            := I + 1;
    end loop;
  
  End if;  RETURN substr(ls_returnstr, 1, 30);
end;

解决方案 »

  1.   

     --汉字处理,如果B_BASIC_SPELLBASE字典表里面查询结果无返回值,我想原样输出这个ls_ch,怎么解决begin
    select WB_CODE
                into ls_temp
                from B_BASIC_SPELLBASE
               where NAME = ls_ch;
    exception
    when others then
     null;
    end;
      

  2.   

    when no_data_found then
      --null;
      ls_returnstr := ls_ch;
    when others then
      raise;
      

  3.   

    --汉字处理,如果B_BASIC_SPELLBASE字典表里面查询结果无返回值,我想原样输出这个ls_ch,怎么解决
              IF v_spellFlag = 0 then
              
                begin
                  select WB_CODE
                    into ls_temp
                    from B_BASIC_SPELLBASE
                   where NAME = ls_ch;
                exception
                  when others then
                    ls_temp := ls_ch;
                end;
              
              else
                --汉字处理,如果B_BASIC_SPELLBASE字典表里面查询结果无返回值,我想原样输出这个ls_ch,怎么解决
                begin
                  select SPELL_CODE
                    into ls_temp
                    from B_BASIC_SPELLBASE
                   where NAME = ls_ch;
                exception
                  when others then
                    ls_temp := ls_ch;
                end;
              End if;
      

  4.   


    ls_returnstr VARCHAR2(50);
      ls_ch        VARCHAR2(20);
      ls_temp      VARCHAR2(20);长度弄长一点啊
      

  5.   

    create or replace function fun_get_querycode(v_string    In VARCHAR2,
                                                 v_spellFlag In number)
      return VARCHAR2 is  I            NUMBER(10);
      li_count     NUMBER(10);
      ls_returnstr VARCHAR2(500);
      ls_ch        VARCHAR2(2000);
      ls_temp      VARCHAR2(200);begin
      IF v_string is not null then
      
        ls_returnstr := '';
        I            := '1';
        li_count     := length(substr(v_string, 1, 30));
      
        WHILE I <= li_count LOOP
        begin
          ls_ch := substr(v_string, I, 1);
          --非汉字 ,不变
          If ASCII(ls_ch) < 128 then
            ls_returnStr := ls_returnStr || upper(ls_ch);
          
          else
          
            IF v_spellFlag = 0 then
              select WB_CODE
              --CASE WB_CODE WHEN '' THEN ls_returnStr ELSE WB_CODE END 
                into ls_temp
                from B_BASIC_SPELLBASE
               where NAME = ls_ch;
            else
            
              select SPELL_CODE
              -- CASE SPELL_CODE WHEN '' THEN ls_ch ELSE SPELL_CODE END 
                into ls_temp
                from B_BASIC_SPELLBASE
               where NAME = ls_ch;
            
            End if; --前面可能是全角的空格 
          
          End if; --前面可能是全角的空格
        
          ls_returnstr := ls_returnStr || '' || ls_temp;
          I            := I + 1;
           exception              when no_data_found              then
                     ls_returnStr := ls_returnStr || upper(ls_ch);
        end;
        end loop;
      
      End if;
      IF v_string is null then
      
        return v_string;
      
      End if; --前面可能是全角的空格
      --前面可能是全角的空格  RETURN substr(ls_returnstr, 1, 30);
    end;出现ORA-06502: PL/SQL: 数字或值错误 :  字符串缓冲区太小
    ORA-06512: 在 "DCP.FUN_GET_QUERYCODE", line 52
    ORA-01403: 未找到数据查看错误堆栈的程序源?怎么解决
      

  6.   

    select WB_CODE into ls_temp
                from B_BASIC_SPELLBASE where NAME = ls_ch;
    改成
    select nvl(max(WB_CODE),ls_ch) into ls_temp
                from B_BASIC_SPELLBASE where NAME = ls_ch;
      

  7.   

    select WB_CODE into ls_temp
                from B_BASIC_SPELLBASE where NAME = ls_ch;
    语句
    和这个
    select nvl(max(WB_CODE),ls_ch) into ls_temp
                from B_BASIC_SPELLBASE where NAME = ls_ch;
    语句有什么区别大哥可以说下吗