从Oracle读取前1kb Blob [英] read first 1kb of a blob from oracle

查看:93
本文介绍了从Oracle读取前1kb Blob的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望仅提取存储的Blob的前1024个字节,而不提取整个文件.原因是我想尽可能快地从文件中提取元数据,而不必选择整个Blob.

I wish to extract just the first 1024 bytes of a stored blob and not the whole file. The reason for this is I want to just extract the metadata from a file as quickly as possible without having to select the whole blob.

我了解以下内容:

select dbms_lob.substr(file_blob, 16,1) 
from file_upload 
where file_upload_id=504;

,将其返回为十六进制.我该怎么做,以便它以二进制数据形式返回而不选择整个blob?

which returns it as hex. How may I do this so it returns it in binary data without selecting the whole blob?

谢谢.

推荐答案

DBMS_LOB.SUBSTR对于BLOB将返回RAW.大多数环境会将其渲染为十六进制. 您可以使用DUMP功能以其他格式查看它.

DBMS_LOB.SUBSTR will, for a BLOB, return a RAW. Most environments will render that in hex. You can use the DUMP function to view it in some other formats.

select dump(dbms_lob.substr(product_image,10,1),10), 
       dump(dbms_lob.substr(product_image,10,1),16), 
       dump(dbms_lob.substr(product_image,10,1),17) 
from APEX_DEMO.DEMO_PRODUCT_INFO
where product_id = 9;

这将以十进制(例如0-255),十六进制和字符返回BLOB的前10个字节.后者可能会在屏幕上抛出一些无法打印的垃圾,并且如果客户端和数据库字符集不匹配,则会进行一些翻译".

This returns the first 10 bytes of the BLOB in decimal (eg 0-255), hex and character. The latter may throw some unprintable garbage to the screen and, if the client and database character sets do not match, undergo some 'translation'.

您可以使用UTL_RAW.CAST_TO_VARCHAR2,它可能会为您提供所需的内容.

You can use UTL_RAW.CAST_TO_VARCHAR2 which may give you what you want.

select utl_raw.cast_to_varchar2(dbms_lob.substr(product_image,10,1)) chr 
from APEX_DEMO.DEMO_PRODUCT_INFO
where product_id = 9

这篇关于从Oracle读取前1kb Blob的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆