tags:

views:

539

answers:

4

I'm trying to execute a SQL query through ODP.NET to create a table, but I always get an ORA-00911 'invalid character' error. The Errors object in the exception always has the text "ORA-00911: invalid character\n", even if there are no linebreaks in the SQL query itself.

The code I'm executing the SQL is this:

using (OracleConnection conn = new OracleConnection(<connection string>) {
using (OracleCommand command = conn.CreateCommand()) {
    conn.Open();
    command.CommandText = queryString;

    command.ExecuteNonQuery();         // exception always gets thrown here
}

queryString contains a single CREATE TABLE statement, which works fine when executed through SQL Developer

EDIT: the SQL I am executing is this:

CREATE TABLE "TESTSYNC"."NEWTABLE" (
  "COL1" NUMBER(*,0) NULL,
  "COL2" NUMBER(*,0) NULL
);

with linebreaks removed

A: 

Should you be using single quotes? or in fact any quotes at all?

Preet Sangha
Could you elaborate on what you mean? The " should be harmless, and, as I said, it works in SQL Developer with the quotes
thecoop
A: 

Your quotes are OK (it just forces Oracle to treat your object names as case sensitive i.e. upper case the way you've written it) but I'm not at all sure you're allowed to define NUMBER that way with a *.

davek
That's the syntax obtained from dbms_metadata.get_ddl where the column is created with datatype INT
thecoop
I've had a play around, and what it's actually complaining about is the ; at the end - removing that makes the sql statement run without problems. That, however, seems incredibly bizarre to me.
thecoop
you could maybe setup TKPROF to run on your database server to see what SQL is being generated by your OracleCommand object (i.e. to see if the ";" is generated automatically)
davek
+2  A: 

Other people have come across this issue - ODP.NET does not support multiple SQL statements in a text command. The solution is to wrap it in a PL/SQL block with EXECUTE IMMEDIATE around each statement. This lack of support for ; seems incredibly boneheaded to me, and has not improved my opinion of the oracle development team.

Furthermore, this seems to be an issue with oracle itself, as I have the same problems with the MS and ODBC oracle clients.

thecoop
A: 

I wonder if it is the "*" in the sql have you tried the call without an * in the create? I bet it is yet another "feature" of the ODP.Net driver

mcauthorn
It's not the *, its the ; at the end that it's complaining about
thecoop
You shouldn't need a ; to execute a statement like that. At least I have never needed one against oracle.
mcauthorn