Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Oracle : Export select statement result set as INSERT SQL Statements similar to SQL developer export

I am looking for a solution to create the SQL INSERT statements using PL/SQL script for the select statement result set. Looking for similar feature available in the SQL Developer tool (export --> format insert) but I want the solution as script rather than using any tool(s).

I have referred the below solution. However, I would like to know whether any better way to do it as the solution is old and not very simple.

EXPORT AS INSERT STATEMENTS: But in SQL Plus the line overrides 2500 characters!

like image 347
notionquest Avatar asked Dec 07 '22 21:12

notionquest


1 Answers

I just found a simple solution for my problem using oracle hint ("insert"). This automatically take care the data type as well. My table has only string and numeric data types, so it works fine for me. I have not tested the solution for other data types. However, I hope it would work for other data types as well.

set linesize 2000
set pagesize 10
spool "c:\myoutput.txt";
select /*insert*/ * from SAMPLE_TABLE;
spool off;
like image 120
notionquest Avatar answered Dec 28 '22 07:12

notionquest