XlbrlX
XlbrlX

Reputation: 763

ORA-00911: invalid character

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.

Upvotes: 63

Views: 55240

Answers (5)

Sohail
Sohail

Reputation: 21

Replace the sqldatasource parameter ? with :Column_name in the delete, update and insert commands.

Upvotes: 0

John Galambos
John Galambos

Reputation: 2821

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;")

Upvotes: 34

inanutshellus
inanutshellus

Reputation: 10001

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.

Upvotes: 1

Akash KC
Akash KC

Reputation: 16310

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.

Upvotes: 1

Antonio Bakula
Antonio Bakula

Reputation: 20693

Remove ; (semi-colon) from the end of SQL string

Upvotes: 180

Related Questions