通过oracle数据库获取输入码
通过oracle数据库获取输入码
1 create or replace function OF_GET_SRM(as_input in varchar2, 2 as_lx in varchar2) 3 return varchar2 is 4 Result varchar2(1000); 5 ls_ch varchar2(10); 6 ls_chnew varchar2(10); 7 begin 8 /*传入两个参数:源字符串,输入码类型(1,拼音,2,五笔,3,数字),返回出对应的汉字输入码*/ 9 /* 有多音字是木有办法识别的哈 */ 10 /*wk 2013.5.06*/ 11 if as_input is null or as_lx is null then 12 result := ''; 13 return result; 14 end if; 15 16 -- 依次处理as_Input中每个字符 17 Result := ''; 18 19 for i in 1..length(as_Input) 20 loop 21 22 ls_ch := substr(as_Input, i, 1) ; 23 24 IF Ascii(ls_ch) < 128 THEN -- 非汉字 25 Result := Result || ls_ch ; --不变 26 ELSE -- 是汉字 27 begin 28 IF as_lx = '1' THEN -- 拼音码 29 Select szsrm03 Into ls_chnew From yygl901 Where szsrm02 = ls_ch; 30 ELSIF as_lx = '2' THEN -- 五笔码 31 Select szsrm04 Into ls_chnew From yygl901 Where szsrm02 = ls_ch; 32 ELSIF as_lx = '3' THEN -- 数字码 33 Select szsrm05 Into ls_chnew From yygl901 Where szsrm02 = ls_ch; 34 END IF; 35 exception 36 when others then 37 Result := Result || ls_ch ; --不变 38 end; 39 Result := Result || ls_chnew ; 40 END IF; 41 42 end loop; 43 44 return(Result); 45 end OF_GET_SRM;