Why the semicolon couldn#39;t place in the CommandText of a OracleCommand when C#(为什么在 C# 时分号不能放在 OracleCommand 的 CommandText 中)
问题描述
C#
如下:
string sql = "select * from table1;";
OracleCommand oc = new OracleCommand(sql , con);
oc.CommandType = CommandType.Text;
oc.ExecuteNonQuery();
结果会是一个错误.
为什么?谁能告诉我原因?
Why? Can any one tell me the reason?
推荐答案
在评论中,我们已经为您找到了答案.只是为了让你得到一个官方的答案",它来自 OracleOverflow 网站(见下文):
In the comments, we've worked out the answer for you. Just so you get an official "answer", here it is from the OracleOverflow site (see below):
一个 OracleCommand 一次只能运行 1 条 sql 或 plsql 语句.无需分隔多个语句.
An OracleCommmand can run only 1 sql or plsql statement at a time. There is no need of separating multiple statements.
分号是用于分隔多个语句的文档的一部分.它不是单个 DDL 语句的一部分.对于 OracleCommand,不需要附加分号,因为它一次只能处理一个语句.
The semicolon is part of documentation to divide multiple statements. It is not part of the single DDL statement. For an OracleCommand there is no need to append a semicolon because it can only handle one statement at a time.
这是原始链接,现在已失效:http://www.oracleoverflow.com/questions/145/running-ddl-through-an-oraclecommand-without-the-semicolon
This was the original link, which is now dead: http://www.oracleoverflow.com/questions/145/running-ddl-through-an-oraclecommand-without-the-semicolon
替代方案:http://web.archive.org/web/20100806014022/http://www.oracleoverflow.com/questions/145/running-ddl-through-an-oraclecommand-without-分号
问题:
尝试通过 OracleCommand 运行一系列 DDL 命令时对象,如果我包含 ORA-00911 'invalid character' 错误最后的分号,即使这是 SQL 语法的一部分文档.这也意味着你只能执行一个SQL一次语句,而不是一次执行整个 SQL 脚本,这对我来说似乎很奇怪.
When trying to run a series of DDL commands through an OracleCommand object, I get an ORA-00911 'invalid character' error if I include the final semicolon, even though this is part of the SQL syntax in the documentation. It also means that you can only execute SQL one statement at a time, rather than executing a whole SQL script at once, which seems very odd to me.
谷歌搜索了一下,我发现一个解决方法是包装 DDL在 EXECUTE IMMEDIATE PL/SQL 语句中,但如果DDL 末尾有一个分号(除了 PL/SQL create 语句,这需要分号).
After googling for a bit, I found that a workaround is to wrap the DDL in an EXECUTE IMMEDIATE PL/SQL statement, but again it fails if the DDL has a semicolon at the end (apart from PL/SQL create statements, which require the semicolon).
有人知道这种行为的原因吗?分号在语法文档,所以我会假设它总是必填,但如果包含分号则失败...
Does anyone know the reason for this behaviour? The semicolon is in the syntax documentation, so I would have assumed it is always required, but it fails if the semicolon is included...
在这里回答:
一个 OracleCommand 一次只能运行 1 条 sql 或 plsql 语句.无需分隔多个语句.
An OracleCommmand can run only 1 sql or plsql statement at a time. There is no need of separating multiple statements.
分号是用于分隔多个语句的文档的一部分.它不是单个 DDL 语句的一部分.对于那里的 OracleCommand不需要附加分号,因为它只能处理一个一次声明.
The semicolon is part of documentation to divide multiple statements. It is not part of the single DDL statement. For an OracleCommand there is no need to append a semicolon because it can only handle one statement at a time.
添加:您可以将多个语句捆绑到 BEGIN ... END 中;块(是的,这以分号结尾).但这种说法应该是DML、DDL 或 PL/SQL 函数调用.您不能捆绑多个 SELECT语句到 BEGIN ... END;阻止.
ADDED: You can bundle more than one statement into an BEGIN ... END; Block (yes, this ends with semicolon). But this statements should be DML, DDL or PL/SQL function calls. You cannot bundle multiple SELECT statements into an BEGIN ... END; Block.
评论:
为什么 OracleCommand 具有一次只能运行 1 条语句的限制?
Why OracleCommand has this limitation of only being able to run 1 statement at a time?
它基于 ADO.Net 中的 DbCommand 规范.这不仅仅是 OracleCommand 的限制.
It's based on DbCommand specification in ADO.Net. It's not a limitation of OracleCommand only.
SqlCommand 允许在一个命令中包含多个语句,这必须只是 SQL Server 的添加".
SqlCommand allows multiple statements in a single command, that must just be an 'addition' for SQL Server.
这篇关于为什么在 C# 时分号不能放在 OracleCommand 的 CommandText 中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:为什么在 C# 时分号不能放在 OracleCommand 的 CommandText 中
基础教程推荐
- rabbitmq 的 REST API 2022-01-01
- 如何在 IDE 中获取 Xamarin Studio C# 输出? 2022-01-01
- 将 XML 转换为通用列表 2022-01-01
- MS Visual Studio .NET 的替代品 2022-01-01
- 有没有办法忽略 2GB 文件上传的 maxRequestLength 限制? 2022-01-01
- 将 Office 安装到 Windows 容器 (servercore:ltsc2019) 失败,错误代码为 17002 2022-01-01
- c# Math.Sqrt 实现 2022-01-01
- 为什么Flurl.Http DownloadFileAsync/Http客户端GetAsync需要 2022-09-30
- SSE 浮点算术是否可重现? 2022-01-01
- 如何激活MC67中的红灯 2022-01-01