正確的要這樣的:
public int update(String ceratedate);
<update id="update" parameterType="String">
update table set ceratedate=to_date(#{ceratedate},'yyyy-mm-dd');
</update>
運行 OK 沒有問題
那我們查詢時,如何將時間格式轉換成字符串呢?要用到to_char()函數
Date格式轉換成String格式
select to_char(a.createdate,'yyyy-mm-dd') from table a
update 表名 set 字段 = to_date('2016/11/10 14:50:15','yyyy/mm/dd hh24:mi:ss');
原因 : ORA-01861: 文字與格式字符串不匹配。這是在處理Oracle的時間字段時,經常會出的一個錯誤。
網上找不到解決的好方法,其實很簡單,在SQL語句中用了TO_CHAR了,那么OracleType就不能是DateTime了,而應該是Varchar。即,
command.Parameters.Add("DATE_PARAM", OracleType。VarChar).Value = DateTime.Now.ToShortDateString();