You are looking for the DECIDE ON VALUE statement.
DECIDE ON FIRST VALUE OF #FLAG
VALUE 'A'
WRITE '#FLAG is A'
VALUE 'B'
WRITE '#FLAG is B'
VALUE 'C':'F'
WRITE '#FLAG is between C and F'
ANY VALUE
WRITE '#FLAG is either A or B or between C and F'
NONE VALUE
WRITE '#FLAG is NEITHER A nor B'
END-DECIDE
There is also DECIDE FOR CONDITION statement that comes in handy when you need to evaluate more complex conditions.
DECIDE FOR FIRST CONDITION
WHEN #FLAG = 'A' AND #PARM = 'X'
WRITE 'Flag A with parameter X selected.'
WHEN #FLAG = 'B' AND #PARM = 'X'
WRITE 'Flag B with parameter X selected.'
WHEN #FLAG = 'C' THRU 'D'
WRITE 'Flag C or D selected.'
WHEN NONE
WRITE 'Invalid #FLAG'
END-DECIDE
Hello.
I badly explained myself.
I meant if it’s possible to use the “case when” command in the select end-select construct in Natural
example:
SELECT
ID_BRAND,
NVL(case when flag_type='A' then sum(price) when flag_type='B' sum(price * 1,22) end,0) as price_tot
FROM
TB1, TB2,
WHERE TB1.ID = TB2.ID
AND ID_BRAND = 'MYBRAND'
*
PERFORM MY_SUBROUTINE
*
END-SELECT
I’m also trying another solution:
WITH_CTE but does not work: error “Variable / field / view must be defined in DEFINE DATA.”
It looks like you might be able to surround your CASE WHEN clause with << >> and Natural will pass everything between the << >> brackets to Oracle without attempting to translate or mess with it. Host variables do need to be prefixed with a : though.