.NET: ora-00911: invalid character when executing multiple Oracle SQL statements
This article will show you how to execute multiple Oracle SQL statements

1 Comments   Posted by LazyAssCoder on Feb 18, 2010   8408 Views   Report Abuse
Tags: ora-00911, Oracle

Bookmark and Share

In .NET, when we try to execute a single Oracle SQL statement with a semicolon at the end. The result will be an oracle error: ora-00911: invalid character.  OK, you figure that one SQL statement doesn't need the semicolon, but what about executing 2 SQL statement in one string for example:


Dim db As Database = DatabaseFactory.CreateDatabase("db")
Dim cmd As System.Data.Common.DbCommand
Dim sql As String = ""

sql = "DELETE FROM iphone_applications WHERE appid = 1; DELETE FROM iphone_applications WHERE appid = 2; "

cmd = db.GetSqlStringCommand(sql)
db.ExecuteNonQuery(cmd)

The code above will give you the same Oracle error: ora-00911: invalid character.

The solution to this problem is to wrap your 2 Oracle SQL statements with a "BEGIN" and "END;" syntax, for example:

sql = "BEGIN DELETE FROM iphone_applications WHERE appid = 1; DELETE FROM iphone_applications WHERE appid = 2; END;"


Comments
  • cmurali on May 21, 2010 04:09:32 PM
    Man, you are a life saver. I had the same problem with my Perl script. I just had one SQL statement terminating with a ;. And taking the extram semi-colon made everything work.

    Cheers,

    -Murali

Login or Register to add a comment.