我在Oracle 10G中创建此视图,我根据日期列进行调整(同时按其他2个分组)。问题是月份会根据我们所处的月份而改变。因此,对于Month1,它将始终是当月的第一个月,Month2将是下个月的第一个月,依此类推。当我硬编码日期时的旋转工作正常,但现在我需要使日期相对,所以我尝试了here的代码:
trunc((sysdate),'dd/mm/yy')
但是我收到了这个错误:
ORA-01898:太多精度说明符 01898. 00000 - "太多的精确说明符" *原因:在尝试截断或舍入日期时,发现了额外的数据 日期格式图片 *操作:检查日期格式图片的语法,然后重试。
我还需要它根据年份移动。所以我们在十一月,到一月份,我需要它到2018年和明年一样。以下是总代码:
select FPC, FWHSE,
Max(DECODE(f.FFPD, trunc((sysdate),'dd/mm/yy'), QTY)) AS MONTH1,
Max(DECODE(f.FFPD, '01-DEC-17', QTY)) AS MONTH2,
Max(DECODE(f.FFPD, '01-JAN-18', QTY)) AS MONTH3,
Max(DECODE(f.FFPD, '01-FEB-18', QTY)) AS MONTH4,
Max(DECODE(f.FFPD, '01-MAR-18', QTY)) AS MONTH5,
Max(DECODE(f.FFPD, '01-APR-18', QTY)) AS MONTH6,
Max(DECODE(f.FFPD, '01-MAY-18', QTY)) AS MONTH7,
Max(DECODE(f.FFPD, '01-JUN-18', QTY)) AS MONTH8,
Max(DECODE(f.FFPD, '01-JUL-18', QTY)) AS MONTH9,
Max(DECODE(f.FFPD, '01-AUG-18', QTY)) AS MONTH10,
Max(DECODE(f.FFPD, '01-SEP-18', QTY)) AS MONTH11,
Max(DECODE(f.FFPD, '01-OCT-18', QTY)) AS MONTH12
from TBL_FORECAST_LATEST f
where FPC = '00002' and FWHSE = 'ROA'
GROUP BY f.FPC, f.FWHSE;