I'm trying to pass parameters using the oracle parameters. It works fine with int types but for my string type it fails with the error:
ORA-01722: invalid number
[OracleException (0x6ba): ORA-01722: invalid number]
OracleInternal.ServiceObjects.OracleCommandImpl.VerifyExecution(OracleConnectionImpl connectionImpl, Int32& cursorId, Boolean bThrowArrayBindRelatedErrors, OracleException& exceptionForArrayBindDML, Boolean& hasMoreRowsInDB, Boolean bFirstIterationDone) +1047
OracleInternal.ServiceObjects.OracleCommandImpl.ExecuteReader(String commandText, OracleParameterCollection paramColl, CommandType commandType, OracleConnectionImpl connectionImpl, OracleDataReaderImpl& rdrImpl, Int32 longFetchSize, Int32 lobPrefetchSize, OracleDependencyImpl orclDependencyImpl, Int64[] scnForExecution, Int64[]& scnFromExecution, OracleParameterCollection& bindByPositionParamColl, Boolean& bBindParamPresent, Boolean isDescribeOnly, Boolean isFromEF) +13029
Oracle.ManagedDataAccess.Client.OracleCommand.ExecuteReader(Boolean requery, Boolean fillRequest, CommandBehavior behavior) +2739
Oracle.ManagedDataAccess.Client.OracleCommand.ExecuteReader() +210
Oracle.ManagedDataAccess.Client.OracleCommand.ExecuteScalar() +406
AspWebReqManagedOracleTest.ParameterizedSql.ExecScalarQuery() in c:\max\git_root\oboe-test\automation\chef-repo\site-cookbooks\fixture\files\default\win_dotnet_sample_apps\AspWebReqManagedOracleTest\ParameterizedSql.aspx.cs:68
AspWebReqManagedOracleTest.ParameterizedSql.Page_Load(Object sender, EventArgs e) in c:\max\git_root\oboe-test\automation\chef-repo\site-cookbooks\fixture\files\default\win_dotnet_sample_apps\AspWebReqManagedOracleTest\ParameterizedSql.aspx.cs:21
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +51
System.Web.UI.Control.OnLoad(EventArgs e) +92
System.Web.UI.Control.LoadRecursive() +54
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +772
Here is my code:
OracleConnection conn = new OracleConnection(connectionString);
try
{
conn.Open();
OracleCommand cmd = new OracleCommand();
cmd.Connection = conn;
cmd.CommandText = "SELECT count(*) from SALES_ADVENTUREWORKS2012.SALESORDERDETAIL where (PRODUCTID=:productid or ROWGUID like :rowguid) and ROWNUM<:limit";
cmd.Parameters.Add(new OracleParameter("limit", 90));
cmd.Parameters.Add(new OracleParameter("productid", 773));
OracleParameter par = new OracleParameter("rowguid", OracleDbType.Char);
par.Value = "hi";
cmd.Parameters.Add(par);
cmd.CommandType = CommandType.Text;
object o = cmd.ExecuteScalar();
}
finally
{
conn.Close();
}
Note that if I pass the string parameter rowguid embedded in the query, it works fine (so there is nothing wrong with 'limit' and 'productid' parameters). I've tried using Char, NChar, NVarchar2; also tried specifying the size. Any ideas what's wrong?
As I said, the query works fine when not using the parameters. In order to make it work, I had to remove the last condition:
where ROWNUM<:limit
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.