C# ORA-00911: 无效字符
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12262145/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ORA-00911: invalid character
提问by XlbrlX
I create two table in my oracle (11g) database like this:
我在我的 oracle (11g) 数据库中创建了两个表,如下所示:
create table "test" ("id" int);
create table test ("id" int);
Then in my C# program there is a problem :
然后在我的 C# 程序中有一个问题:
OracleConnection conn = new OracleConnection(-myConnectionString-);
conn.Open();
OracleCommand command = new OracleCommand("select * from test;", conn);
var v = command.ExecuteReader();
OracleCommand command = new OracleCommand("select * from \"test\";", conn);
var v = command.ExecuteReader();
for both command.ExecuteReader() I have an "ORA-00911: invalid character" error.
对于这两个 command.ExecuteReader() 我有一个“ORA-00911:无效字符”错误。
采纳答案by Antonio Bakula
Remove ; (semi-colon) from the end of SQL string
消除 ; (分号)从 SQL 字符串的末尾开始
回答by Akash KC
Why are you using semicolon in the query...It just be taken as invalid character..... You have to remove the semicolon(;) from the query and do like this:
为什么你在查询中使用分号...它只是被视为无效字符.....你必须从查询中删除分号(;)并这样做:
OracleConnection conn = new OracleConnection(-myConnectionString-);
conn.Open();
OracleCommand command = new OracleCommand("select * from test", conn);
var v = command.ExecuteReader();
OracleCommand command = new OracleCommand("select * from \"test\"", conn);
var v = command.ExecuteReader();
For more detail of this error, you can read here.
有关此错误的更多详细信息,您可以阅读此处。
回答by inanutshellus
This isn't this guy's problem, but hopefully this will help someone out there:
这不是这个人的问题,但希望这会帮助那里的人:
I often have this problem with single quotes hidden inside inline comments, like so:
我经常遇到隐藏在行内注释中的单引号的问题,如下所示:
select foo
from bar
where
/* some helpful comment with a "can't" or somesuch */
baz='qux'
The unmatched single quote in the comment causes all kinds of drama, and oracle doesn't go out of its way to help you figure that out.
评论中无与伦比的单引号引起了各种戏剧性的影响,oracle 不会特意帮助您解决这个问题。
回答by John Galambos
In case other people wind up here looking for how to include multiple statements in a single command, you need to wrap your statements within beginand end. This will stop the invalid character errors due to the semi-colons. For example:
如果其他人在这里寻找如何在单个命令中包含多个语句,您需要将您的语句包装在begin和end 中。这将停止由于分号导致的无效字符错误。例如:
var command = new OracleCommand(@"
begin
select * from test;
select * from test2;
end;")
回答by Sohail
Replace the sqldatasourceparameter ?with :Column_namein the delete, updateand insertcommands.
更换的SqlDataSource参数?与:Column_name在delete,update和insert命令。

