I create two table in my oracle (11g) database like this:
create table "test" ("id" int);
create table test ("id" int);
Then in my C# program there is a problem :
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.
Remove ; (semi-colon) from the end of SQL string
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 begin and end. This will stop the invalid character errors due to the semi-colons. For example:
var command = new OracleCommand(@"
begin
select * from test;
select * from test2;
end;")
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.
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.
Replace the sqldatasource parameter ?
with :Column_name
in the delete
, update
and insert
commands.
来源:https://stackoverflow.com/questions/12262145/ora-00911-invalid-character