2

I have an Oracle 11g table with the following column names and types:

ID VARCHAR2(32 BYTE)
VERSION VARCHAR2(12 BYTE)

I am trying to get bind variables to work in an Oracle parameterized command for Update statements on this table using ODP.NET and C#, but I'm having no luck. Here is the code I am using:

string constr = gconstr + "; Data Source=" + db;
OracleConnection con = new OracleConnection(constr);
con.Open();
ddiId = "WS_5043";
ddiVer = "1.0.3";

string UPDATE_CLOB_QUERY = "UPDATE :ddiTable SET version=:ddiVer WHERE id=:ddiId";

Oracle.DataAccess.Types.OracleXmlType ret;
OracleCommand oracleCommand2 = new OracleCommand(UPDATE_CLOB_QUERY, con);
oracleCommand2.Parameters.Clear();
oracleCommand2.Parameters.Add("ddiId", OracleDbType.Varchar2, ParameterDirection.Input).Value = ddiId;
oracleCommand2.Parameters.Add("ddiTable", OracleDbType.Varchar2, ParameterDirection.Input).Value = ddiTable;
oracleCommand2.Parameters.Add("ddiVer", OracleDbType.Varchar2, ParameterDirection.Input).Value = ddiVer;
oracleCommand2.ExecuteNonQuery();
oracleCommand2.Dispose();

When I run the above code in VS2010, I get the following Oracle error:

ORA-01036: illegal variable name/number

However, when I remove the bind variable declarations in the SQL then the above works i.e.

string UPDATE_CLOB_QUERY = "UPDATE wstable SET version='1.0.2' WHERE id='WS_5043'";

What am I doing wrong?

I need to know how to get bind variables and parameterized Oracle commands working with SQL Update commands such as the one above as a requirement, because I will begin eventually updating large clobs in other tables (and concatenating the clobs as strings in SQL will of course cause size limit errors). So getting this to work will be the first victory.

2
  • 1
    I don't think you can use a parameter for the table name. Commented Jan 8, 2013 at 22:33
  • 1
    I did find [this answer elsewhere on the site][1] that may help you. [1]: stackoverflow.com/questions/1179652/… Commented Jan 8, 2013 at 22:37

1 Answer 1

2

In this line;

oracleCommand2.Parameters.Add("ddiTable", OracleDbType.Varchar2, ParameterDirection.Input).Value = ddiTable;

You actually try to add as a parameter your table name (ddiTable). You can't do that. And there is no point to add your query table name as a parameter. And If you want to use Parameters.Add() method with 3 parameters, you must use as parameters like;

public OracleParameter Add(
    string parameterName,
    OracleType dataType,
    int size
)

That's the only fits overloading method. There is no overloading for taking third parameter type of ParameterDirection.Input of Parameters.Add() method.

I need to know how to get bind variables and parameterized Oracle commands working with SQL Update commands such as the one above as a requirement.

May I suggest you to read these;

Sign up to request clarification or add additional context in comments.

1 Comment

Fantastic, thanks for taking the time to point me in the right direction.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.