Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Re: Converting Teradata Case to Oracle Decode
the "group by" clause must contain all of the non-aggregate
expressions in the select list.
oracle doesn't support the "named" clause like teradata does. and you can't refer to an expression with a number in the "group by" clause (like you can in the "order by" clause.) and, as you've discovered, the "case" expression is not supported either. at least not in version 8.0 or earlier.
what you can do is nest the decode statements; this may work in your case.
i recall there is an issue with the datatypes of the expressions in the decode having to match; there's a problem if they don't.
anyway, i've not tested this, but it may get you started...
SELECT PRICE_PLAN_CODE
, SUM(DECODE(CYCLE_RUN_MONTH,'08' ,DECODE(CYCLE_RUN_YEAR,'2001',REPORTED_TIME_DUR ,0),0)) AUG_USAGE , SUM(DECODE(CYCLE_RUN_MONTH,'09' ,DECODE(CYCLE_RUN_YEAR,'2001',REPORTED_TIME_DUR ,0),0)) SEP_USAGE
SELECT PRICE_PLAN_CODE
, SUM(DECODE(CYCLE_RUN_MONTH||CYCLE_RUN_YEAR,'082001' ,REPORTED_TIME_DUR,0) AUG_USAGE , SUM(DECODE(CYCLE_RUN_MONTH||CYCLE_RUN_YEAR,'092001' ,REPORTED_TIME_DUR,0) SEP_USAGEFROM LD_ACCESS_VIEWS.VSLU001_USAGE_DETAIL GROUP BY PRICE_PLAN_CODE