Skip to content
Advertisement

How to generate INSERT Statements with Subqueries in Oracle SQL Developer?

I need to move some data from Environment A to Environment B. So far, so easy. But some of the columns have FK Constraints and unfortunately the lookup data is already on Environment B and has different PKs. Lucky me, there are other unique columns I could do a mapping on. Therefore I wonder if SQL Developer has an export feature which allows me to replace certain column values by subqueries. To make it clear, I’m looking for a SQL Developer Feature, Query or similar which generates INSERT Statements that look like this:

My best approach was to try to generate them by hand, like this:

Which is absolutely a pain. Do you know something better to achive this without approaching the other db?

Advertisement

Answer

Simple write a query that produces the required data (with the mapped key) using a join of both tables.

For example (see the sample data below) such query (mapping the unique_value to the id):

Now you can use the normal SQL Developer export feature in the INSERT format, which would yield following script – if you want to transer it to other DB or insert it direct with INSERT ... SELECT.

Sample Data

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement