为什么分号不能放在CommandText的OracleCommand当C# [英] why the semicolon couldn't place in the CommandText of a OracleCommand when C#

查看:271
本文介绍了为什么分号不能放在CommandText的OracleCommand当C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么 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):


OracleCommmand只能运行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-the-semicolon

问题:


当尝试通过OracleCommand
对象运行一系列DDL命令时,如果我包括
最后一个分号,即使这是
文档中的SQL语法的一部分,ORA-00911'invalid character'错误。这也意味着你一次只能执行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.

在googling了一点后,我发现一个解决方法是将DDL
包装在EXECUTE IMMEDIATE PL / SQL语句中,但是如果
DDL在分号end(除了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...

在这里回答:


OracleCommmand一次只能运行一个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.

ADDED:多个语句转换为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.

这篇关于为什么分号不能放在CommandText的OracleCommand当C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆