共计 4960 个字符,预计需要花费 13 分钟才能阅读完成。
本篇内容主要讲解“怎么创建 UNWRAP 函数”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让丸趣 TV 小编来带大家学习“怎么创建 UNWRAP 函数”吧!
创建 UNWRAP 函数
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;
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
/* Formatted on2011/8/18 13:00:16 (QP5 v5.163.1008.3004) */
CREATE OR REPLACE JAVA SOURCE NAMED UNWRAPPER
import java.io.*;
import java.util.zip.*;
public class UNWRAPPER { public static String Inflate(byte[] src) {
try { ByteArrayInputStream bis = new ByteArrayInputStream(src);
InflaterInputStream iis = new InflaterInputStream(bis);
StringBuffer sb = new StringBuffer();
for(int c = iis.read(); c != -1; c = iis.read()) { sb.append((char)c);
}
return sb.toString();
} catch (Exception e) { }
return null;
}
public static byte[] Deflate(String src, int quality) {
try { byte[] tmp = new byte[src.length() + 100];
Deflater defl = new Deflater(quality);
defl.setInput(src.getBytes( UTF-8));
defl.finish();
int cnt = defl.deflate(tmp);
byte[] res = new byte[cnt ];
for(int i = 0; i cnt; i++)
res = tmp;
return res;
} catch (Exception e) { }
return null;
}
ALTER JAVA SOURCE UNWRAPPER COMPILE
/* Formatted on2011/8/18 13:02:57 (QP5 v5.163.1008.3004) */
-- 为了输出中文,要修改 java 过程
CREATE OR REPLACE JAVA SOURCE NAMED UNWRAPPER
import java.io.*;
import java.util.zip.*;
public class UNWRAPPER { public static String Inflate(byte[] src) {
try { ByteArrayInputStream bis = new ByteArrayInputStream( src );
InflaterInputStream iis = new InflaterInputStream( bis );
StringBuffer sb = new StringBuffer();
for(int c = iis.read(); c != -1; c = iis.read()) { sb.append((char) c);
}
String hello = new String(sb.toString().getBytes(iso8859-1), GBK
return hello;
} catch(Exception e) { }
return null;
}
public static byte[] Deflate(String src, int quality) {
try { byte[] tmp = new byte[src.length() + 100];
Deflater defl = new Deflater(quality);
defl.setInput(src.getBytes( UTF-8));
defl.finish();
int cnt = defl.deflate(tmp);
byte[] res = new byte[cnt];
for(int i = 0; i cnt; i++)
res = tmp;
return res;
} catch (Exception e) { }
return null;
}
ALTER JAVA SOURCE UNWRAPPER COMPILE
/* Formatted on2011/8/18 13:00:41 (QP5 v5.163.1008.3004) */
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;
CODE VARCHAR(512);
BEGIN
CODE := 3D6585B318DBE287F152AB634BB5A05F7D687B9B24C228678ADEA4261E03EB176F343E7A3FD2A96A0FE935561FB14D1078D975F6BC4104816106F9ADD6D5297E869E79E505BA84CC6E278EB05DA8F39FD0A271B858DD2C38994C480755E4538C46B62DA5AF322240DC50C3A1258B9C16605CCFFD0C981CD4376D3C3A30E86C3147F533DA43C8E35E1994ECE6A39514E09D64FA5915C52FCABB0BDFF297BF0A76B449445A1DF0009621807F1A82394FC1A7D70DD1D8FF139370EE5BEFBE09B97772E7B254B72AC7739066200E51EDF87C8F2EF412C62B83CDACCB3BC44EC069366202AE88FCAA4208A64557D39ABDE1238D924A1189746B91FBFEC901EA1BF7CE --sys.idltranslate 表内容存到字符数组
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)) -- 保存去掉前边 20 行的 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) / 256;
VWRAPPEDTEXT :=
FOR I IN 0 .. NLEN LOOP
--ifi nLen then
VWRAPPEDTEXT := VWRAPPEDTEXT ||
UTL_ENCODE.BASE64_DECODE(UTL_RAW.CAST_TO_RAW(SUBSTRB(VTRIMTEXT,
256 * I + 1,
256)));
--else
--vWrappedtext:=vWrappedtext||utl_encode.base64_decode(utl_raw.cast_to_raw(substrb(vtrimtext,64*i+1 ))) ;
--endif;
--DBMS_OUTPUT.PUT_LINE(vWrappedtext);
END LOOP;
--vWrappedtext:=substr(vWrappedtext,41);
NLEN := LENGTH(VWRAPPEDTEXT) / 2 - 1;
VLZINFLATESTR :=
FOR NLOOP IN 20 .. NLEN LOOP
-- 从第 41 字节开始
VCHAR := SUBSTRB(VWRAPPEDTEXT, NLOOP * 2 + 1, 2);
VLZINFLATESTR := VLZINFLATESTR ||
SUBSTR(CODE, TO_NUMBER(VCHAR, XX) * 2 + 1, 2); -- 从字符串变量匹配
--DBMS_OUTPUT.PUT_LINE(vLZinflatestr);
END LOOP;
--DBMS_OUTPUT.PUT_LINE(vLZinflatestr);
DBMS_OUTPUT.PUT_LINE(AMOSUNWRAPPER.INFLATE(VLZINFLATESTR));
/
使用
exec unwrap( SYS , DBMS_ROWID , PACKAGE BODY
select * from dba_source where name= DBMS_ROWID
到此,相信大家对“怎么创建 UNWRAP 函数”有了更深的了解,不妨来实际操作一番吧!这里是丸趣 TV 网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!
正文完