使用VB6在Oracle中插入多行

发布于 2024-10-02 05:44:17 字数 1330 浏览 7 评论 0原文

我正在尝试使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

无人接听 2024-10-09 05:44:17

您尚未指定 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.

习惯成性 2024-10-09 05:44:17

您可能需要单独执行每个语句,例如:

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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文