ORA-00933: SQL 命令未正确结束

发布于 2024-07-04 16:38:57 字数 537 浏览 10 评论 0原文

我正在使用 OLEDB 提供程序将 ADO.Net 连接到 Oracle 数据库。 在我的循环中,我正在执行插入:

insert into ps_tl_compleave_tbl values('2626899', 0, TO_DATE('01/01/2002', 'MM/DD/YYYY'), 'LTKN', 'LTKN', '52', TO_DATE('01/01/2002', 'MM/DD/YYYY'), 16.000000, 24.000)insert into ps_tl_compleave_tbl values('4327142', 0, TO_DATE('03/23/2002', 'MM/DD/YYYY'), 'LTKN', 'LTKN', '51', TO_DATE('03/23/2002', 'MM/DD/YYYY'), 0.000000, 0.000)

第一个插入成功,但第二个插入出现错误:

ORA-00933: SQL command not properly ended

我做错了什么?

I'm using OLEDB provider for ADO.Net connecting to an Oracle database. In my loop, I am doing an insert:

insert into ps_tl_compleave_tbl values('2626899', 0, TO_DATE('01/01/2002', 'MM/DD/YYYY'), 'LTKN', 'LTKN', '52', TO_DATE('01/01/2002', 'MM/DD/YYYY'), 16.000000, 24.000)insert into ps_tl_compleave_tbl values('4327142', 0, TO_DATE('03/23/2002', 'MM/DD/YYYY'), 'LTKN', 'LTKN', '51', TO_DATE('03/23/2002', 'MM/DD/YYYY'), 0.000000, 0.000)

The first insert succeeds but the second one gives an error:

ORA-00933: SQL command not properly ended

What am I doing wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(10

瀞厅☆埖开 2024-07-11 16:38:57

在.net中,当我们尝试执行单个以分号结尾的Oracle SQL语句时。 结果将是 oracle 错误:ora-00911:无效字符。 好的,您认为一条 SQL 语句不需要分号,但是如果在一个字符串中执行 2 条 SQL 语句呢?例如:

Dim db As Database = DatabaseFactory.CreateDatabase("db")
Dim cmd As System.Data.Common.DbCommand
Dim sql As String = ""

sql = "DELETE FROM iphone_applications WHERE appid = 1; DELETE FROM iphone_applications WHERE appid = 2; "

cmd = db.GetSqlStringCommand(sql)
db.ExecuteNonQuery(cmd)

上面的代码将给您相同的 Oracle 错误:ora-00911:无效字符。

此问题的解决方案是使用 BEGINEND; 语法包装 2 个 Oracle SQL 语句,例如:

sql = "BEGIN DELETE FROM iphone_applications WHERE appid = 1; DELETE FROM iphone_applications WHERE appid = 2; END;"

Courtesy: http://www.lazyasscoder .com/Article.aspx?id=89&title=ora-00911%3A+invalid+character+when+executing+multiple+Oracle+SQL+语句

In .net, when we try to execute a single Oracle SQL statement with a semicolon at the end. The result will be an oracle error: ora-00911: invalid character. OK, you figure that one SQL statement doesn't need the semicolon, but what about executing 2 SQL statement in one string for example:

Dim db As Database = DatabaseFactory.CreateDatabase("db")
Dim cmd As System.Data.Common.DbCommand
Dim sql As String = ""

sql = "DELETE FROM iphone_applications WHERE appid = 1; DELETE FROM iphone_applications WHERE appid = 2; "

cmd = db.GetSqlStringCommand(sql)
db.ExecuteNonQuery(cmd)

The code above will give you the same Oracle error: ora-00911: invalid character.

The solution to this problem is to wrap your 2 Oracle SQL statements with a BEGIN and END; syntax, for example:

sql = "BEGIN DELETE FROM iphone_applications WHERE appid = 1; DELETE FROM iphone_applications WHERE appid = 2; END;"

Courtesy: http://www.lazyasscoder.com/Article.aspx?id=89&title=ora-00911%3A+invalid+character+when+executing+multiple+Oracle+SQL+statements

傲娇萝莉攻 2024-07-11 16:38:57

对我来说,您似乎在两个语句之间缺少 ;
插入 ps_tl_compleave_tbl 值('2626899', 0, TO_DATE('01/01/2002', 'MM/DD/YYYY'), 'LTKN', 'LTKN', '52', TO_DATE('01/ 01/2002', 'MM/DD/YYYY'), 16.000000, 24.000)
<代码>;
插入 ps_tl_compleave_tbl 值('4327142', 0, TO_DATE('03/23/2002', 'MM/DD/YYYY'), 'LTKN', 'LTKN', '51', TO_DATE('03/ 23/2002', '月/日/年'), 0.000000, 0.000)
<代码>;
尝试添加 ; 并告诉我们。

To me it seems you're missing a ; between the two statements:
insert into ps_tl_compleave_tbl values('2626899', 0, TO_DATE('01/01/2002', 'MM/DD/YYYY'), 'LTKN', 'LTKN', '52', TO_DATE('01/01/2002', 'MM/DD/YYYY'), 16.000000, 24.000)
;
insert into ps_tl_compleave_tbl values('4327142', 0, TO_DATE('03/23/2002', 'MM/DD/YYYY'), 'LTKN', 'LTKN', '51', TO_DATE('03/23/2002', 'MM/DD/YYYY'), 0.000000, 0.000)
;
Try adding the ; and let us know.

肩上的翅膀 2024-07-11 16:38:57

第一个插入后的分号?

semi colon after the first insert?

谎言 2024-07-11 16:38:57

Oracle 中的分号 ';' 仅在sqlplus中使用。 当您使用 ODBC/JDBC、OLEDB 等时,您不会在语句末尾添加分号。 在上面的情况下,您实际上正在执行 2 个不同的语句,因此处理问题的最佳方法是使用 2 个语句,而不是尝试组合成单个语句,因为您不能使用分号。

In Oracle the semi-colon ';' is only used in sqlplus. When you are using ODBC/JDBC, OLEDB, etc you don't put a semi-colon at the end of your statement. In the above case you are actually executing 2 different statements so the best way to handle the problem is use 2 statements instead of trying to combine into a single statement since you can't use the semi-colon.

2024-07-11 16:38:57

除了分号问题之外,我强烈建议您研究一下绑定变量。 不使用它们可能会导致数据库性能问题。 代码也趋向于更加简洁。

In addition to the semicolon problem, I strongly recommend you look into bind variables. Failing to use them can cause database performance problems down the road. The code also tends to be cleaner.

爱的那么颓废 2024-07-11 16:38:57

ADO.NET OLE DB 提供程序用于通用数据访问,您的数据库没有特定的提供程序。 对于 Oracle 数据库连接,优先使用 OracleConnection 等而不是 OleDbConnection。

The ADO.NET OLE DB provider is for generic data access where you don't have a specific provider for your database. Use OracleConnection et al in preference to OleDbConnection for an Oracle database connection.

长途伴 2024-07-11 16:38:57

这是一个长期的尝试,但在第一次插入中,sql 日期格式对英国/美国都有效,如果 Oracle 数据库设置为英国日期格式,则第二次插入无效,我意识到您已经使用了 TO_DATE 函数,但我没有看看还有什么...

It's a long shot but in the first insert the sql date format is valid for both uk/us, the second insert is invalid if the Oracle DB is setup for UK date format, I realise you have used the TO_DATE function but I don't see anything else ...

囚你心 2024-07-11 16:38:57

在我的循环中,我没有重新初始化我的 StringBuilder ...因此我发布了多个插入语句。

还是要谢谢你的帮助!!

In my loop I was not re-initializing my StringBuilder ...thus the multiple insert statement I posted.

Thanks for your help anyway!!

南…巷孤猫 2024-07-11 16:38:57

Oracle SQL 使用分号 ; 作为语句结束标记。

您需要添加 ; 在打扰之后插入语句。

注意:这还假设 ADODB 将允许在一次调用中进行 2 次插入。

另一种方法可能是将两个调用包装在一个块中,

BEGIN
      insert (...) into (...);
      insert (...) into (...);
END;

Oracle SQL uses a semi-colon ; as its end of statement marker.

you will need to add the ; after bother insert statments.

NB: that also assumes ADODB will allow 2 inserts in a single call.

the alternative might be to wrap both calls in a block,

BEGIN
      insert (...) into (...);
      insert (...) into (...);
END;
毅然前行 2024-07-11 16:38:57

问题可能是您将一个为 null 的参数变量插入到查询中。 这就是我的问题所在。 一旦我为参数指定了空字符串的默认值,它就起作用了。

The issue may be that you have a parameter variable that is null being inserted into the query. That was what my problem was. Once I gave the parameter a default value of empty string, it worked.

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