• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
Techgoeasy

Techgoeasy

Learn Oracle, PHP, HTML,CSS,Perl,UNIX shell scripts

  • Home
  • Oracle
    • Oracle database
    • Oracle Ebusiness Suite
    • Oracle weblogic
    • Oracle Performance Tuning
    • Oracle Hyperion
    • Oracle Cloud Tutorials
  • SQL
  • interview questions
  • Linux
  • PHP and HTML
  • Downloads
  • General
Home » Oracle » Oracle Database » How to select blob from table

How to select blob from table

April 1, 2022 by techgoeasy Leave a Comment

Many times, we may need to check the data stored in the blob field in the table. If you just do select, it will not give you proper output. Here are some of the ways on How to select blob from table

Using sqlplus

select BLOB_FIELD from <table name> where ID = '<row id>';

SELECT DBMS_LOB.SUBSTR(BLOB_FIELD_NAME) FROM <table name>;

It will read the first 2000 chars in the blob
SELECT utl_raw.cast_to_varchar2(dbms_lob.substr(<YOUR_BLOB_FIELD>,2000,1)) FROM <YOUR_TABLE>;

This converts data to the database character set. it returned the value in VARCHAR2.This will be limited to 4000 Bytes

select TO_CHAR(BLOB_FIELD) from <table name> where ID = '<row id>';

SELECT TO_CHAR(dbms_lob.substr(BLOB_FIELD, 3900)) FROM <table name>;

Using Toad or SQL developer

In Toad or SQL developer, if you select the blob column, it will show a blob in the text. And then you can double click to open in a text editor to view it

How to read LOB data using plsql

set serveroutput on size 1000000;
declare
  my_lob BLOB;
  Buffer      RAW(255);
  Amount      BINARY_INTEGER := 255;
  Position    INTEGER := 1;
begin
   select <blob column> into my_lob 
   from <table name>
   where id = &enter_id;
 
   dbms_lob.open(my_lob, dbms_lob.lob_readonly);
   DBMS_OUTPUT.PUT_LINE('Start of data');

   loop
      DBMS_LOB.READ(my_lob, Amount, Position, Buffer);
      /* Process the buffer: */
      DBMS_OUTPUT.PUT_LINE(utl_raw.cast_to_varchar2(Buffer));
      Position := Position + Amount;
   end loop;

   dbms_lob.close(my_lob);
  EXCEPTION
    WHEN NO_DATA_FOUND THEN
      DBMS_OUTPUT.PUT_LINE('End of data');
end;
/

I hope you like this content. Please do provide the feedback

Also Reads
How to find space usage of lob segments in Oracle database
how to move lob segment from one tablespace to another

Filed Under: Oracle, Oracle Database

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar



Subscribe to our mailing list

Enter your email address to subscribe to this blog and receive notifications of new posts by email

Recent Posts

  • Oracle tkprof utility
  • What is Skew in Database?
  • how to find file based on size in linux
  • SQL trace, 10046 event in Oracle
  • How to use sed replace string in file

Copyright © 2023 : TechGoEasy

  • Hire me
  • Privacy Policy
  • Contact Us
  • New? Start Here
  • About Us