Insert multiple rows in Oracle using VB6
I am trying to insert multiple rows in a table using BeginTrans...CommitTrans.
Below is code snippet:For i = 1 To 5
SQL = SQL & "Insert into TestTable(Field1,Field2,Field3) Values ('Col" & i & "','Col" & i + 1 & "','Col" & i + 2 & "')" & vbCrLf
Next i
conn.BeginTrans
conn.Execute SQL
conn.CommitTrans
and following is the SQL prepared using the loop
Insert into TestTable(Field1,Field2,Field3) Values 开发者_StackOverflow社区('Col1','Col2','Col3')
Insert into TestTable(Field1,Field2,Field3) Values ('Col2','Col3','Col4')
Insert into TestTable(Field1,Field2,Field3) Values ('Col3','Col4','Col5')
Insert into TestTable(Field1,Field2,Field3) Values ('Col4','Col5','Col6')
Insert into TestTable(Field1,Field2,Field3) Values ('Col5','Col6','Col7')
When I run conn.CommitTrans
I get ORA-00911: Invalid character
If I modify the SQL as
Insert into TestTable(Field1,Field2,Field3) Values ('Col1','Col2','Col3');
Insert into TestTable(Field1,Field2,Field3) Values ('Col2','Col3','Col4');
Insert into TestTable(Field1,Field2,Field3) Values ('Col3','Col4','Col5');
Insert into TestTable(Field1,Field2,Field3) Values ('Col4','Col5','Col6');
Insert into TestTable(Field1,Field2,Field3) Values ('Col5','Col6','Col7');
I get ORA-00933: SQL command not properly ended.
If I update further and replace ";" with "/" again get same error Any help is greatly appreciated. ThanX in advance...You haven't specified what TestTable actually is (type of fields, etc). However, I would start by seeing if you can type the insert command into a standard Oracle client (e.g. TOAD)?
If you can't then check for any triggers or constraints on the table.
You probably need to execute each statement separately, e.g.:
conn.BeginTrans
For i = 1 To 5
SQL = "Insert into TestTable(Field1,Field2,Field3) Values ('Col" & i & "','Col" & i + 1 & "','Col" & i + 2 & "')"
conn.Execute SQL
Next i
conn.CommitTrans
精彩评论