How do I get textual contents from BLOB in Oracle SQL(如何从 Oracle SQL 中的 BLOB 获取文本内容)
问题描述
我试图从 SQL 控制台查看 Oracle BLOB 中的内容.
我知道它包含的文本体量有点大,我只想查看文本,但以下查询仅表明该字段中有一个 BLOB:
select BLOB_FIELD from TABLE_WITH_BLOB where ID = '
';
我得到的结果并不完全符合我的预期:
<前>BLOB_FIELD-----------------------oracle.sql.BLOB@1c4ada9
那么我可以做什么样的魔法咒语才能将 BLOB 变成它的文本表示?
PS:我只是想从 SQL 控制台(Eclipse Data Tools)查看 BLOB 的内容,而不是在代码中使用它.
首先,您可能希望将文本存储在 CLOB/NCLOB 列中,而不是专为二进制数据设计的 BLOB(您的查询将使用 CLOB,顺便说一句).
以下查询将让您看到 blob 中文本的前 32767 个字符(最多),前提是所有字符集都兼容(存储在 BLOB 中的文本的原始 CS,用于 VARCHAR2 的数据库的 CS) :
select utl_raw.cast_to_varchar2(dbms_lob.substr(BLOB_FIELD)) from TABLE_WITH_BLOB where ID = '';
I am trying to see from an SQL console what is inside an Oracle BLOB.
I know it contains a somewhat large body of text and I want to just see the text, but the following query only indicates that there is a BLOB in that field:
select BLOB_FIELD from TABLE_WITH_BLOB where ID = '<row id>';
the result I'm getting is not quite what I expected:
BLOB_FIELD ----------------------- oracle.sql.BLOB@1c4ada9
So what kind of magic incantations can I do to turn the BLOB into it's textual representation?
PS: I am just trying to look at the content of the BLOB from an SQL console (Eclipse Data Tools), not use it in code.
First of all, you may want to store text in CLOB/NCLOB columns instead of BLOB, which is designed for binary data (your query would work with a CLOB, by the way).
The following query will let you see the first 32767 characters (at most) of the text inside the blob, provided all the character sets are compatible (original CS of the text stored in the BLOB, CS of the database used for VARCHAR2) :
select utl_raw.cast_to_varchar2(dbms_lob.substr(BLOB_FIELD)) from TABLE_WITH_BLOB where ID = '<row id>';
这篇关于如何从 Oracle SQL 中的 BLOB 获取文本内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何从 Oracle SQL 中的 BLOB 获取文本内容


- 如何将 Byte[] 插入 SQL Server VARBINARY 列 2021-01-01
- 在SQL中,如何为每个组选择前2行 2021-01-01
- 如何使用 pip 安装 Python MySQLdb 模块? 2021-01-01
- SQL 临时表问题 2022-01-01
- 使用 Oracle PL/SQL developer 生成测试数据 2021-01-01
- 以一个值为轴心,但将一行上的数据按另一行分组? 2022-01-01
- 导入具有可变标题的 Excel 文件 2021-01-01
- 远程 mySQL 连接抛出“无法使用旧的不安全身份验证连接到 MySQL 4.1+"来自 XAMPP 的错误 2022-01-01
- 如何将 SonarQube 6.7 从 MySQL 迁移到 postgresql 2022-01-01
- 更改自动增量起始编号? 2021-01-01