Building the insert statements, I want to pass a table name and where clause and have it return all of the insert statements neccessary to recreate those records in another database which has that same table.
Main Topics
Browse All TopicsI need to figure out if it is possible to dynamically create Insert statements from an Oracle database source. The resulting insert statements would then also need to be translated to work on either Oracle or SQL Server (2 separate results). The data types of potential fields are limited to (VARCHAR2, DATE, NUMBER). I know there are easier ways to move data but my requirements are that the result is a .SQL file which can then be executed at will. I am working on Oracle 10 and SQL Server 2005.
Ideally the result would be a stored procedure, function or .NET code and would accept the table name as well as the where clause to limit the exact rows needed.
Let me know if any additional information is required to help answer this.
Thanks,
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
well, you know the INSERT syntax:
INSERT INTO destination_table_name
( col1, col2, col3, col4 .... et c. ... )
VALUES
( value1, value2, value3, value4 .... etc ... )
so, I repeat: where is the problem.
you know the destination table.
you know the destination column names
you queried the source values
the only things you must watch out, for the values in the sql insert, is
* NULL
VALUES ( ... , NULL , ... )
* numerical values (decimals)
VALUES ( ... , 120000.23434 , ... )
* strings (single quotes around, and 2 single quotes for a string value containing single quotes
VALUES ( ... , 'Mc''Donalds', ... )
* dates (implicit data type conversion)
Oracle:
VALUES ( ... , TO_DATE('2009-08-01', 'YYYY-MM-DD') , ...
SQL Server:
VALUES ( ... , CONVERT(datetime, '2009-08-01', 120) , ...
hope this helps
Ok i will try and rephrase again, I won't know the column names, number of columns or the type of each column because like i said I want the actual table to be a parameter that means I want to use it on many tables on demand as I need in my .Net application. Of course I can hard code for each table but that is precisely what I am trying to avoid.
will the data type in the source table be effectively the same as in the destination table?
if yes, you can of course know the column names and data types, by querying the catalog of the table.
in oracle, check the COL view:
http://ss64.com/orad/COL.h
The data types will be the exact same in the Oracle destination and effectively the same in the SQL Server destination. I know I can build the routine to do this by querying the database catalog I was just hoping someone had already done the grunt work and had an available Stored Procedure or code block to handle it. It seems that I am going to have to bite the bullet and write it myself.
Thanks for your help, I actually did find a procedure that works when using SQL server as it's source but it is far from compatible in oracle.
what about this starter:
http://pandazen.wordpress.
just adjust it for the sql server version output ...
I see. the VARCHAR2(4000) is not big enough :)
I solved that, in one of my other developments, with a function that returned data in a "pipelined" manner, aka like a rowset (but not with a cursor):
http://www.akadia.com/serv
for your, you could return 1 table value per "returned row", for example...
Business Accounts
Answer for Membership
by: angelIIIPosted on 2009-08-10 at 23:03:56ID: 25066473
so, what exactly is the problem?
? connecting to the oracle database?
? querying according to the input parameters?
? writing to the 2 .sql files?
? building the insert statement?