Home > Database > Mysql Tutorial > How to Extract Text from a BLOB in Oracle SQL?

How to Extract Text from a BLOB in Oracle SQL?

Barbara Streisand
Release: 2024-12-27 14:11:09
Original
949 people have browsed it

How to Extract Text from a BLOB in Oracle SQL?

Extracting Textual Contents from BLOB in Oracle SQL

In Oracle SQL, LOB (Large Object) types, such as BLOB, are used to store binary data. To access the textual contents of a BLOB, you can use the following query:

select utl_raw.cast_to_varchar2(dbms_lob.substr(BLOB_FIELD)) from TABLE_WITH_BLOB where ID = '<row id>';
Copy after login

Explanation:

  • utl_raw.cast_to_varchar2(): Converts the binary BLOB data into a VARCHAR2 type, which represents textual data.
  • dbms_lob.substr(): Extracts a substring from the BLOB starting from a specified position.
  • BLOB_FIELD: The name of the BLOB column containing the textual data.
  • TABLE_WITH_BLOB: The name of the table that contains the BLOB column.
  • ID: The unique identifier of the row in the table.

Example:

Assuming you have a table named MY_TABLE with a BLOB column named TEXT_FIELD that contains a text document, the following query will extract and display the first 32767 characters of the text:

select utl_raw.cast_to_varchar2(dbms_lob.substr(TEXT_FIELD)) from MY_TABLE where ID = 1;
Copy after login

The above is the detailed content of How to Extract Text from a BLOB in Oracle SQL?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template