Somehow or the other, I learned that I can simply pass in parameters into an Oracle stored proc and it would be able to convert the parameters into the appropriate type. Well I am running into issues dealing with that. I am getting an “ORA-00900: invalid SQL statement” returned to me… I am guessing it is because I am attempting to pass in strings… That is what I read somewhere anyway…
“http://www.dba-oracle.com/sf_ora_00900_invalid_sql_statement.htm”
What is the technique for inputing Oracle parameters into a stored proc and then executing that stored proc using .net Variables? Will I have to convert the .net strings into ODP data types? I hope not…
Here is what my code generall does…
XmlAttribute xAttribute;
using (OracleConnection conn = new OracleConnection(ConfigurationManager.ConnectionStrings["ACODBConnectionString"].ConnectionString))
{
using (OracleCommand cmd = new OracleCommand(sProc, conn))
{
int i = 0;
foreach (string path in paths)
{
string OracleParam;
xAttribute = AcoXMLDoc.SelectSingleNode(string.Format("//dataTemplateSpecification/templates/template/elements/element[@name='{0}']", path)).Attributes["value"];
if ((xAttribute.Value == null))
{
OracleParam = "";
cmd.Parameters.Add(colName[i], OracleParam);
}
else
{
OracleParam = xAttribute.Value;
cmd.Parameters.Add(colName[i], OracleParam);
}
i++;
}
conn.Open();
outcome = cmd.ExecuteNonQuery();
}
}
As you can see, I am pulling the values out of an XML document so naturally the values are going to be strings… It is going to suck so much a$$ if I have to figure out how to change the strings into the appropriate data type…
The cmd.Parameters.Add() expects an object that is a parameter (not the value of the parameter)
so this is doable, with a few caveats but here is a test case:
set up the Oracle bit:
now for the .net bit:
Now things to take note of:
then you will have your data:
EDIT
Per your comment; in the parameters in PL/SQL when you use
you are actually just tying that datatype to the column’s data type in the table (this allows the column to be changed and it won’t break the package).
for the example I provided:
is the same as
Not sure of an ‘anonymous/generic datatype’ that you can pass in