oracle实现PDU编码
54powerman
一 UCS2编码函数
create or replace function UCS2Encode(orgString varchar2) return varchar2 is
Result varchar2(255);
dst varchar2(60);
tmp varchar2(2);
pos integer;
begin
dst:='';
pos:=length(orgString);
while pos>0
loop
tmp:=substr(orgString,pos,1);
Result:=trim(upper(to_char(ascii(tmp),'0xxx'))) || Result;
pos:=pos-1;
end loop;
return(Result);
end UCS2Encode;
二 UCS2解码函数
create or replace function UCS2Decode(pduString varchar2)
return varchar2 is
ret varchar2(400);
v_msg varchar2(400);
v_pos number;
v_tmp varchar2(5);
begin
if encode < 0 or encode > 2 then
return '';
end if;
ret := '';
v_msg:=pduString;
--如果不含有UDH头,不需要下面的三行
--v_pos := to_number(substr(pduString,1,2),'0x');
--v_pos:=v_pos*2+3;
--v_msg:=substr(pduString,v_pos,length(pduString)-v_pos+1);
v_pos:=1;
while v_pos < length(v_msg) loop
v_tmp := substr(v_msg, v_pos, 4);
if encode = 1 then
ret := ret || trim(to_char(ascii(v_tmp), '0x'));
elsif encode = 2 then
v_tmp:='/'||v_tmp;
ret := ret || unistr(v_tmp);
end if;
v_pos := v_pos + 4;
end loop;
ret:=upper(ret);
return(ret);
end UCS2Decode;
未完,更新中...