在Oracle中从十六进制编码的CLOB转换为BLOB [英] Convert from hex-encoded CLOB to BLOB in Oracle
本文介绍了在Oracle中从十六进制编码的CLOB转换为BLOB的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在CLOB中存储了一些十六进制形式的大型二进制内容,并希望将其转换为BLOB,其中十六进制代码是实际的二进制字节编码:
I have some large binary content in hex form stored in a CLOB and want to convert that to a BLOB where the hex code is actual binary byte encoding:
DECLARE
-- This would be my 8 byte hex-encoded binary content. Real content is much bigger
c CLOB := 'cafebabe12345678';
b BLOB;
BEGIN
-- Need the implementation of this function
b := hex_to_blob(c);
END;
/
使用PL/SQL在Oracle中最简单的方法是什么?
What's the easiest way to do that in Oracle, using PL/SQL?
推荐答案
所需的功能可能如下所示:
The desired function could look like this:
CREATE OR REPLACE
FUNCTION hex_to_blob (hex CLOB) RETURN BLOB IS
b BLOB := NULL;
s VARCHAR2(4000 CHAR) := NULL;
l NUMBER := 4000;
BEGIN
IF hex IS NOT NULL THEN
dbms_lob.createtemporary(b, FALSE);
FOR i IN 0 .. LENGTH(hex) / 4000 LOOP
dbms_lob.read(hex, l, i * 4000 + 1, s);
dbms_lob.append(b, to_blob(hextoraw(s)));
END LOOP;
END IF;
RETURN b;
END hex_to_blob;
这篇关于在Oracle中从十六进制编码的CLOB转换为BLOB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文