Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I insert into a BLOB column from an insert statement in sqldeveloper?

Is it possible to insert into a BLOB column in oracle using sqldeveloper?

i.e. something like:

insert into mytable(id, myblob) values (1,'some magic here'); 
like image 301
chris Avatar asked Sep 20 '11 17:09

chris


People also ask

Can we INSERT blob in SQL?

The database server provides SQL functions that you can call from within an INSERT statement to import and export BLOB or CLOB data, otherwise known as smart large objects. For a description of these functions, see Smart large object functions.

How do I create a BLOB column in Oracle?

You can initialize a BLOB column value by using the function EMPTY_BLOB() as a default predicate. Similarly, a CLOB or NCLOB column value can be initialized by using the function EMPTY_CLOB() . You can also initialize a LOB column with a character or raw string less than 4000 bytes in size.


1 Answers

To insert a VARCHAR2 into a BLOB column you can rely on the function utl_raw.cast_to_raw as next:

insert into mytable(id, myblob) values (1, utl_raw.cast_to_raw('some magic here')); 

It will cast your input VARCHAR2 into RAW datatype without modifying its content, then it will insert the result into your BLOB column.

More details about the function utl_raw.cast_to_raw

like image 109
Nicolas Filotto Avatar answered Oct 28 '22 06:10

Nicolas Filotto