create or replace package amosunwrapper is function deflate( src in varchar2 ) return raw; function deflate( src in varchar2, quality in number ) return raw; function inflate( src in raw ) return varchar2; end; /
create or replace package body amosunwrapper is function deflate( src in varchar2 ) return raw is begin return deflate( src, 6 ); end;
function deflate( src in varchar2, quality in number ) return raw as language java name 'UNWRAPPER.Deflate( java.lang.String, int ) return byte[]';
function inflate( src in raw ) return varchar2 as language java name 'UNWRAPPER.Inflate( byte[] ) return java.lang.String';
declare nCnt integer; nLoop integer; nSLoop integer; nCharmax integer; nCharmin integer; vChar Varchar2(3); cursor getchar is with src AS ( select 'procedure '||vChar txt from dual ), wrap as ( select src.txt , dbms_ddl.wrap( 'create ' || src.txt ) wrap from src ), subst as (select substr( utl_encode.base64_decode( utl_raw.cast_to_raw(rtrim( substr( wrap.wrap, instr( wrap.wrap, chr( 10 ), 1, 20 ) + 1 ), chr(10) ) ) ), 41 ) x,amosunwrapper.deflate( wrap.txt || chr(0), 9 ) d from wrap ) select substr( x, r*2 - 1, 2 ) xr ,substr( d, r*2 - 1, 2 ) dr from subst , ( select rownum r from dual connect by rownum <= ( select length( x ) / 2 from subst ) ); begin nCharmax:=97; nCharmin:=122; For nLoop In 97..122 Loop For nSloop In 0..99 Loop vChar := chr(nLoop)||to_char(nSloop); For abc In getchar Loop Select Count(*) Into nCnt From sys.idltranslate WHERE c_base64decode = abc.xr; If nCnt < 1 Then Insert INTO sys.idltranslate VALUES (abc.xr,abc.dr); Commit; Else Select Count(*) Into nCnt From sys.idltranslate WHERE c_base64decode = abc.xr AND c_lzdeflatecode=abc.dr; If nCnt < 1 Then DBMS_OUTPUT.PUT_LINE('wrong orginal char:'||vchar||' hex base64:'||abc.xr); End If; End If; End Loop; End Loop; End Loop; end; /
等待运行一段时间
筛选出sys.idltranslate表前10条数据:
1
select * from sys.idltranslate where rownum<=10;
运行上面这段SQL大概会产生200多条记录:
1
select count(*) c_base64decode from sys.idltranslate;
set serveroutput on; create directory FILEPATH as 'D:\sql_files'; --创建一个路径FILEPATH grant read,write on directory FILEPATH to sys; --给用户sys授予路径读写的权限 create or replace procedure unwrap(o in varchar,n in varchar, t in varchar) as vWrappedtext Varchar2(32767); vtrimtext Varchar2(32767); vChar Varchar2(2); vRepchar Varchar2(2); vLZinflatestr Varchar2(32767); nLen Integer; nLoop Integer; nCnt Integer; l_file utl_file.file_type;
type vartab is table of varchar2(2) index by varchar2(2); mytbl vartab; cursor getchar is select C_BASE64DECODE xr,C_LZDEFLATECODE dr from sys.idltranslate; Begin for i in getchar loop --sys.idltranslate表内容存到字符数组 mytbl(i.xr):=i.dr; end loop; vtrimtext:=''; select count(*) into nCnt from DBA_SOURCE Where owner=o And Name = n And Type = t ; if nCnt >0 and nCnt <5 then for i in 1..nCnt loop if i=1 then select rtrim( substr( TEXT, instr( TEXT, chr( 10 ), 1, 20 ) + 1 ), chr(10) ) --保存去掉换行的BASE64码正文 into vLZinflatestr from DBA_SOURCE Where owner = o And Name = n And Type = t and line=i; else select text into vLZinflatestr from DBA_SOURCE Where owner = o And Name = n And Type=t and line=i; end if; vtrimtext:=vtrimtext||vLZinflatestr; end loop; end if; vtrimtext:=replace(vtrimtext,chr(10),''); nLen := Length(vtrimtext)/64 ; vWrappedtext :=''; for i in 0..nLen loop if i< nLen then vWrappedtext:=vWrappedtext||utl_encode.base64_decode( utl_raw.cast_to_raw(substrb(vtrimtext,64*i+1 , 64 ))) ; else vWrappedtext:=vWrappedtext||utl_encode.base64_decode( utl_raw.cast_to_raw(substrb(vtrimtext,64*i+1 ))) ; end if; --DBMS_OUTPUT.PUT_LINE(vWrappedtext); End Loop; --vWrappedtext:=substr(vWrappedtext,41); nLen := Length(vWrappedtext)/2 - 1; vLZinflatestr :='';
For nLoop In 20..nLen Loop --从第21字节开始 vChar := Substrb(vWrappedtext,nLoop*2+1,2); /* Select Count(*) Into nCnt From SYS.IDLTRANSLATE Where C_BASE64DECODE=vChar; If nCnt <> 1 Then DBMS_OUTPUT.PUT_LINE('SUBSTATION TABLE WARNING: Count not find following char--'||vChar); Return; Else Select C_LZDEFLATECODE Into vRepchar From SYS.IDLTRANSLATE Where C_BASE64DECODE=vChar; End If; */ vLZinflatestr := vLZinflatestr || mytbl(vChar); --从字符数组匹配 --DBMS_OUTPUT.PUT_LINE(vLZinflatestr); End Loop; --DBMS_OUTPUT.PUT_LINE(vLZinflatestr); l_file := utl_file.fopen('FILEPATH', 'unwrap_text.sql', 'W'); --给文件变量赋予一个初值unwrap_text.sql,最后一个参数W表示写入 utl_file.put_line(l_file, amosunwrapper.inflate(vLZinflatestr)); utl_file.fclose(l_file);--关闭文件 DBMS_OUTPUT.PUT_LINE(amosunwrapper.inflate(vLZinflatestr)); End; /
create or replace function test_f(hy in varchar) return varchar as x varchar(2); begin select case when hy >='01' and hy<= '05' then 1 when hy >='06' and hy<= '11' then 2 when hy >='13' and hy<= '43' then 3 when hy >='44' and hy<= '46' then 4 when hy >='47' and hy<= '50' then 5 when hy >='51' and hy<= '59' then 6 when hy >='60' and hy<= '62' then 7 when hy ='63' or hy = '65' then 8 when hy >='66' and hy<= '67' then 9 when hy >='68' and hy<= '71' then 10 when hy >='72' and hy<= '72' then 11 when hy >='73' and hy<= '74' then 12 when hy >='75' and hy<= '78' then 13 when hy >='79' and hy<= '81' then 14 when hy >='82' and hy<= '83' then 15 when hy >='84' and hy<= '84' then 16 when hy >='85' and hy<= '87' then 17 when hy >='88' and hy<= '92' then 18 when hy >='93' and hy<= '98' then 19 else null end into x from dual; return x; end; /