60

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.

XlbrlX
  • 703
  • 1
  • 6
  • 10

5 Answers5

173

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

Antonio Bakula
  • 19,349
  • 5
  • 73
  • 97
  • Just came accross. What if I need to execute 2 Update statements on 2 different tables on the same command? Putting semicolon produces an error. – SleepNot Mar 08 '13 at 09:31
  • its because the parameters are from a datareader and i need to execute 2 insert statements on 2 different tables while the datareader is reading. – SleepNot Mar 11 '13 at 04:04
  • I must say that I don't understant your scenario completly, better ask another question, and see this https://groups.google.com/forum/?fromgroups=#!topic/microsoft.public.data.odbc/hHwYSbmsvqc – Antonio Bakula Mar 11 '13 at 10:00
  • 13
    Sorry for swearing, but seriously wtf? Why wouldn't they accept semicolons in the query string? I wasted one and a half hours trying to figure out what was wrong with my very very simple db code. – Kang Min Yoo Mar 21 '14 at 05:28
  • 1
    I wanna upvote this a zillion times!!! Lost 2 hours beating my head, validating each field for nothing... Studpid Oracle Adapter! (and developer =/) – eestein Aug 07 '14 at 14:20
  • 26
    Why can't Oracle just say which character is invalid in their error message? – Jeff Bloom Mar 30 '15 at 18:31
  • Thank you! Was helpful to this date! :D – Indigo May 14 '15 at 20:48
  • 2
    I waste the whole afternoon to recognize my issue. I write multiple statements in a single command at firstly, so it's really a nightmare if a developer meet unfriendly 'invalid character' error message. – Bes Ley Sep 21 '15 at 10:27
  • They don't tell you what character is invalid because, compared to MSSQL, Oracle is trash. – Lucas925 Feb 11 '19 at 23:32
33

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;")
John Galambos
  • 2,763
  • 2
  • 22
  • 23
1

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.

Akash KC
  • 15,121
  • 5
  • 33
  • 56
1

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.

inanutshellus
  • 8,481
  • 9
  • 48
  • 69
-1

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

Frits
  • 6,116
  • 10
  • 39
  • 50
Sohail
  • 11
  • 3