1、iBatis會自動緩衝每條查詢語句的列名映射,所有如果你動態產生列名的話就有可能造成查詢列名無效的問題。
ibaits 會緩衝查詢的meta資訊,在產生動態列時一定要加上
remapResults="true"。
2、oracle查詢sql中,想使用數字或特殊字元作列的別名時,可以用“”引起來。
3、oracle行轉列,事先需要確定查詢的列資訊,在列用sum和decode函數匯總
如:
<select id="queryZjhHzByRq" parameterClass="com.athena.paicjh.entity.paiczjhjs.Paiczjhjs" resultClass="java.util.HashMap" remapResults="true">select zcwlh || '(' || sum(sl) || ')' zcwlh<iterate property="beanList"> ,sum(decode(rksj, #beanList[].rksj#, sl, 0)) "$beanList[].rksj$" </iterate> from (select to_char(jz.rksj, 'yyyy-mm-dd') rksj, jz.zcwlh, sum(nvl(jz.sl, 0)) sl, jz.ptbz from jh_zjh jz where jz.usercenter = #usercenter# and jz.rksj >= to_date(#start#, 'yyyy-mm-dd') and jz.rksj <![CDATA[<=]]> to_date(#end#, 'yyyy-mm-dd') <isNotEmpty prepend="and" property="zcwlh">zcwlh like $zcwlh$</isNotEmpty> group by jz.rksj, jz.zcwlh, jz.ptbz union all select to_char(to_date(rksj, 'yyyymm'), 'yyyy-mm') rksj, zcwlh, sum(nvl(sl, 0)) sl, '2' ptbz from jh_yzjh where usercenter = #usercenter# and drbz = '0' and to_date(rksj || '01', 'yyyymmdd') >= to_date(#start#, 'yyyy-mm-dd') and to_date(rksj || '01', 'yyyymmdd') <![CDATA[<=]]> to_date(#end#, 'yyyy-mm-dd') <isNotEmpty prepend="and" property="zcwlh">zcwlh like $zcwlh$</isNotEmpty> group by rksj, zcwlh) t group by zcwlh order by zcwlh</select>