JAVA中ORA-56900: pivot|unpivot 操作内不支持绑定变量
ORA-56900: pivot|unpivot 操作内不支持绑定变量
问题说明:oracle在使用行专列函数(pivot|unpivot),不允许pivot函数内动态绑定参数,即不支持:select * from table pivot(sum(column) for c1 in (?,?)) 这种写法。
使用场景及遇到问题
由于报表需求需要统计一年的数据:年份是由客户选的,会动态变
实际数据如上,会有指定的月份数据为空,由于觉得java去处理麻烦,就用oracle行转列行数补充日期为空的数据
理想状态:
实现方式
select * from (
select count(*) sumNum,to_char(appl_time,'yyyy-MM') dateStr from OPM_CIM_ANALYSIS_RESULT t0
where ADMITTANCEACCESS in ('Y','N') and appl_time is not null
group by to_char(appl_time,'yyyy-MM') order by to_char(appl_time,'yyyy-MM') desc
) pivot (sum(sumNum) for dateStr in
<foreach collection="dateList" item="item" open="(" close=")" separator=",">
#{
item}
</foreach>
)
遇到问题:ORA-56900: pivot|unpivot 操作内不支持绑定变量
2021-06-21 10:22:07 | DEBUG | http-nio-7779-exec-1 | com.dfwy.cim.dao.mamagement.ManagerSumResultDao.querySurveyInfo | ==> Preparing: select * from ( select