rumi
rumi

Reputation: 3298

ORA-00936: missing expression using Entity framework update statement

I'm new to using ORACLE with entity framework 5. Trying a simple update statement which won't work and I m getting an error "ORA-00936: missing expression"

Entities context = new Entities();

var Description="UpdateTesting";
var Id = "1";

string UpdateSqlString = @"Update SOURCE Set DESCRIPTION={0} where SOURCEID={1}";

int RowsUpdated = context.Database.ExecuteSqlCommand(UpdateSqlString, Description, Id);

context.SaveChanges();

I have also tried the following but still getting the same error

 Entities context = new Entities();

 var Description = "UpdateTesting";
 var Id = "1";

 var sql = @"Update SOURCE Set DESCRIPTION = @DESCRIPTION WHERE SOURCEID = @Id";

 int RowsUpdated = context.Database.ExecuteSqlCommand(sql, new OracleParameter("DESCRIPTION", Description),
                                                                  new OracleParameter("Id", Id));
 context.SaveChanges();

I have now tried with the following syntax but nothing happens after the ExecuteSqlCommand and the application probably goes in some not-ending loop

var Description="UpdateTesting";
var SOURCEId = "1";

var sql = "Update SOURCE SET DESCRIPTION = :Description WHERE SOURCEID = :SOURCEId";

 int RowsUpdated=context.Database.ExecuteSqlCommand(
            sql,
            new OracleParameter(":Description", Description),
            new OracleParameter(":SOURCEId", SOURCEId));

I can provide SQL Create table script If that would help resolve this.

Any ideas? thanks

Upvotes: 3

Views: 2027

Answers (3)

Francois
Francois

Reputation: 43

Have you try this? without colon

    var Description="UpdateTesting";
var SOURCEId = "1";

var sql = "Update SOURCE SET DESCRIPTION = :Description WHERE SOURCEID = :SOURCEId";

 int RowsUpdated=context.Database.ExecuteSqlCommand(
            sql,
            new OracleParameter("Description", Description),
            new OracleParameter("SOURCEId"   , SOURCEId));

Upvotes: 3

Rob
Rob

Reputation: 85

Rather than using {0} use :0 instead.

Entities context = new Entities();

var Description="UpdateTesting";
var Id = "1";

string UpdateSqlString = @"Update SOURCE Set DESCRIPTION=:0 where SOURCEID=:1";

int RowsUpdated = context.Database.ExecuteSqlCommand(UpdateSqlString, Description, Id);

context.SaveChanges();

Upvotes: 2

VMAtm
VMAtm

Reputation: 28355

I think that you have to add ' symbol for your update script as the SQL doesn't recognize it as string, like this:

Update SOURCE Set DESCRIPTION='{0}' where SOURCEID={1}

Try to edit other expressions accordingly.

Update:

May be, your problem is in table name (SOURCE may be a reserved keyword, and doesn't be recognized as table name) . Try to wrap it in "", like this:

Update "SOURCE" Set DESCRIPTION='{0}' where SOURCEID={1}

Upvotes: 0

Related Questions