How to export clob field datas in oracle sql developer

Prashobh Chandran picture Prashobh Chandran · Feb 15, 2017 · Viewed 40.9k times · Source

How to export clob field data's in oracle sql developer. Currently clob field data's can't export in oracle sql developer.

Answer

Alex Poole picture Alex Poole · Feb 15, 2017

If you don't want to (or can't) export and import your data, and really want it as a set of insert statements, you can use SQL Developer's built-in formatting tools to automatically split your CLOBs into multiple chunks that are small enough to be valid as string literals, and then spool the result to a file:

spool clob_export.sql
select /*insert*/ * from your_table;
spool off

With more recent versions you can use the sqlformat command to control the output format without needing to modify the query; this is equivalent:

set sqlformat insert
spool clob_export.sql
select * from your_table;
spool off

The generated insert statements will look something like:

REM INSERTING into YOUR_TABLE
SET DEFINE OFF;
Insert into YOUR_TABLE (ID,CLOB_COLUMN) values (1,TO_CLOB('... up to 4k of characters with quotes escaped ...')
|| TO_CLOB('... up to 4k of characters with quotes escaped ...')
|| TO_CLOB('... up to 4k of characters with quotes escaped ...')
...
|| TO_CLOB('... up to 4k of characters with quotes escaped ...'));