1

I have a datatable of 3 columns ID (int), Name (string), Status (string) and of 1000 rows .. and a table with 4 columns seq (generated from SEQR.NEXTVAL), ID, Name, Status.

I want to insert all 1000 rows in a single query. I mean avoiding 1000 times database hit using loops for performance issue.

Constraints are:

  1. I am using Oracle 10g
  2. stored procedures, cursors not allowed
  3. To temporary table creation allowed as DBA is from client side so I can't create DB tables from my side

Any suggestion with proper code? I am using Oracle client and DbCommand object

3 Answers 3

2

So just use a single SQL statement, right?

insert into table_a (seq_col, id, name, status)
select seqr.nextval, id, name, status
from table_b;
Sign up to request clarification or add additional context in comments.

1 Comment

But here one table is datatable another is database table
0

If I understood your question correctly, you can use a Select statement in your insert statement:

Insert into table2
  Select SEQR.NEXTVAL, tab1.*
    from table1 as tab1

1 Comment

@RahulChowdhury So you want to write a query from .Net side and insert a 1000 rows in one trip to the server. I am now aware of a way to do that. Why cant you use stored procedures?
0

Use Oracle array DML. YOu just fill the column arrays in a loop from your code, and the send everything as a single INSERT statement. Anyway IMHO 1000 INSERTs with a properly written query using bind variables won't hit performance issues. You'll get them if you don't use bind variables and commit each time...

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.