oracle 資料庫base64位轉碼解碼
oracle 轉碼函式
CREATE OR REPLACE FUNCTION base64decode(p_clob CLOB)
RETURN CLOB
IS
l_blob CLOB;
l_raw RAW(32767);
l_amt NUMBER := 7700;
l_offset NUMBER := 1;
l_temp VARCHAR2(32767);
BEGIN
BEGIN
DBMS_LOB.createtemporary (l_blob, FALSE, DBMS_LOB.CALL);
LOOP
DBMS_LOB.read(p_clob, l_amt, l_offset, l_temp);
l_offset := l_offset + l_amt;
l_raw := UTL_ENCODE.base64_decode(UTL_RAW.cast_to_raw(l_temp));
DBMS_LOB.append (l_blob, TO_CLOB(utl_raw.cast_to_varchar2(l_raw)));
END LOOP;
EXCEPTION
WHEN NO_DATA_FOUND THEN
NULL;
END;
RETURN l_blob;
END;
oracle 解碼函式:
CREATE OR REPLACE FUNCTION base64encode(p_clob CLOB)
RETURN CLOB
IS
l_blob CLOB;
l_raw RAW(32767);
l_amt NUMBER := 7700;
l_offset NUMBER := 1;
l_temp VARCHAR2(32767);
BEGIN
BEGIN
DBMS_LOB.createtemporary (l_blob, FALSE, DBMS_LOB.CALL);
LOOP
DBMS_LOB.read(p_clob, l_amt, l_offset, l_temp);
l_offset := l_offset + l_amt;
l_raw := UTL_ENCODE.base64_encode(UTL_RAW.cast_to_raw(l_temp));
DBMS_LOB.append (l_blob, TO_CLOB(utl_raw.cast_to_varchar2(l_raw)));
END LOOP;
EXCEPTION
WHEN NO_DATA_FOUND THEN
NULL;
END;
RETURN l_blob;
END;
java 解碼函式
public String decodeStr(String encodeStr){undefined
byte[] b=encodeStr.getBytes();
Base64 base64=new Base64();
b=base64.decode(b);
String s="";
try {undefined
s = new String(b,"GBK");
} catch (UnsupportedEncodingException e) {undefined
// TODO Auto-generated catch block
e.printStackTrace();
}
logger.debug("value-------------------------------------:"+s);
return s;
}