1. 程式人生 > >查詢條件為日期時報’無效的列型別'錯誤方法解決

查詢條件為日期時報’無效的列型別'錯誤方法解決

查詢條件使用到日期的時候報出


實體類裡欄位都是正確對應的

SQL語句形式類似為:

select tv.*
	 from account_sel_view tv  
	 where 1=1 
	 <if test="regstartDate!=null and regstartDate!=''">
		and startDate >= to_date('#{regstartDate}','yyyy-mm-dd HH24:MI:SS')
	 </if>
	 <if test="regendDate!=null and regendDate!=''">
		and startDate <= to_date('#{regendDate}','yyyy-mm-dd HH24:MI:SS') 
	 </if>
	 <if test="allNumLow!=null and allNumLow!=''">
		and dealSum >= TO_NUMBER(#{allNumLow})
	 </if>
	 <if test="allNumHigh!=null and allNumHigh!=''">
		and dealSum <= TO_NUMBER(#{allNumHigh}) 
	 </if>

	

以上問題是因為:



to_date的引數不可加上' '。

正確寫法為:

<if test="regstartDate!=null and regstartDate!=''">
	and startDate >= to_date(#{regstartDate},'yyyy-mm-dd HH24:MI:SS')
</if>
<if test="regendDate!=null and regendDate!=''">
	and startDate <= to_date(#{regendDate},'yyyy-mm-dd HH24:MI:SS') 
</if>