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(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 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
            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;
请问  --汉字 ,不变
      但B_BASIC_SPELLBASE表里的name不存在这个查询的字段,没有返回值请问 我怎么 把查询到的汉字不变 输出来 。

解决方案 »

  1.   

    select SPELL_CODE
                into ls_temp
                from B_BASIC_SPELLBASE
               where NAME = ls_ch; 
    这里查询 结果没有返回的列,我想把
    select  fun_get_querycode(列名,1)
    FROM 表
    查询的列名值 赋值给ls_temp 这个变量 怎么赋值呢?
      

  2.   

      /*-------------------------------------------------------------------------
      || 函数名称 :转换成拼音码或者五笔码
      || 功能描述 :将传入的字符串转换成相应的拼音码或者五笔码
      ||
      || 参数描述 :参数标识      输入/输出       类型          名称
      ||            -------------------------------------------------------------
      ||            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;
    好吧我想我说的不太正确