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

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

问题描述

为什么分号(';')无法在的CommandText 放置的OracleCommand时 C#

why the semicolon(';') couldn't place in the CommandText of a OracleCommand when C#

只是舔以下

string sql = "select * from table1;";
OracleCommand oc = new OracleCommand(sql , con);
oc.CommandType = CommandType.Text;
oc.ExecuteNonQuery();

结果将证明是一个错误。

the result would turn out to be a error.

为什么?任何一个可以告诉我原因吗?

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

编辑:这是原来的链接,也就是现在死了:<一href="http://www.oracleoverflow.com/questions/145/running-ddl-through-an-oraclecommand-without-the-semicolon" rel="nofollow">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

替代:<一href="http://web.archive.org/web/20100806014022/http://www.oracleoverflow.com/questions/145/running-ddl-through-an-oraclecommand-without-the-semicolon" rel="nofollow">http://web.archive.org/web/20100806014022/http://www.oracleoverflow.com/questions/145/running-ddl-through-an-oraclecommand-without-the-semicolon

问:

在通过的OracleCommand试图运行一系列的DDL命令   对象,我得到一个ORA-00911无效字符错误,如果我包括   最后一个分号,即使这是在SQL语法部分   文档。这也意味着,你只能执行SQL 1   在一次声明中,而不是执行整个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.

google搜索了一下后,我发现一个解决方法是换了DDL   在EXECUTE即时PL / SQL语句,但再次失败,如果   DDL有一个分号结尾(除了PL / SQL创建语句,   需要分号)。

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.

新增:您可以捆绑多个语句到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?

它基于的DbCommand规范ADO.Net。这不是唯一的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.

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

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