使用VB6在Oracle中插入多行
我正在尝试使用 BeginTrans...CommitTrans 在表中插入多行。
下面是代码片段:
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
以下是使用循环准备的 SQL
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')
当我运行 conn.CommitTrans
时,我得到 ORA-00911:无效字符
时修改 SQL
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');
如果我在得到 ORA-00933 :SQL 命令不正确结束。
如果我进一步更新并替换“;”使用“/”再次出现相同的错误
非常感谢任何帮助。
提前ThanX...
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 ('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...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您尚未指定 TestTable 实际是什么(字段类型等)。不过,我首先会看看您是否可以在标准 Oracle 客户端(例如 TOAD)中键入插入命令?
如果不能,请检查表上是否有任何触发器或约束。
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.: