问题
I made an extensive search but I couldn't find any example about this.
I have a .NET variable of type TimeSpan and I need to put it into an IntervalDayToSecond
record of an Oracle DB.
Referring to http://docs.oracle.com/html/B14164_01/featOraCommand.htm this page, it should be possible to pass a TimeSpan object as an OracleParameter and get it inserted into my Oracle DB in a record of IntervalDayToSecond
type.
This is the code:
OracleParameter t = new OracleParameter("PAR_T", _msg.t);
I tried it in every way, also explicitly specifying the DBType (it shouldn't be necessary):
OracleParameter t = new OracleParameter("PAR_T", _msg.t);
taxi.OracleDbType = OracleDbType.IntervalDS;
I always get the same error from Oracle:
Devart.Data.Oracle.OracleException: ORA-01861: literal does not match format string
I can't understand how to make it work; I use dozens of parameters in this application (of type String
, Integer
, Date
) and they all are working. On Google I can't find a single example of someone using c# TimeSpan
as Parameter. Has anyone ever tried this?
回答1:
Ok, it was definitely my fault.
Good old OracleParameter
was doing his job nicely; the problem was elsewhere in the query.
So I hereby confirm that it is possible to bind a TimeSpan variable to an Oracle Interval Day To Second
record.
string s = "00:20";
TimeSpan ts = TimeSpan.parse(s);
OracleParameter op = new OracleParameter("PAR_T", ts);
This creates a parameter named PAR_T
which can be used in a query to insert a value into a Interval Day To Second
record.
来源:https://stackoverflow.com/questions/14317721/using-oracleparameter-with-c-sharp-timespan-literal-does-not-match