Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How To Generate Insert Statements From Query Using SQL/SQLPlus

littlecatNov 4 2022

Hi
Apologies if this has been answered.
I have bunch of tables that I wish to generate insert statements from select * from table query. I know in tools such as SQL Developer can export results as insert statements and can use /* insert */ in SQL Developer script. Is there equivalent for SQL in SQL Plus.
I am not even sure how to generate scripts to achieve this from dba_tab_columns as this return one row per column.
I wish to automate this. Cannot use data pump, export, sql loader etc.
Eg
Query as below
select *
from emp
To produce
Insert into EMP (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) values (7839,'KING','PRESIDENT',null,to_date('17/NOV/1981','DD/MON/RRRR'),5000,null,10);
..

Comments
Post Details
Added on Nov 4 2022
6 comments
16,937 views