DB/Oracle

DECODE

Edward. K 2007. 10. 22. 18:50
반응형

DECODE(value, if1, then1, if2, then2,.....,else)

--> value의 데이터가 if1일 경우 then1으로 바꾸어주고, value데이터가 if2일 경우

      그 값을 then2로 바꾸어준다. 또 나머지 ifx 값들도 thenx값들로 바꾸어준다.


decode(a, b, c, d)
--> a 와 b 가 같으면 c 를 리턴, 아니면 d를 리턴


decode(a,b,c,d,e)
--> a 와 b 가 같으면 c를 리턴, a와 d 랑같으면 e를 리턴...

case 문으로 표현하면

첫번째 decode는
case when a=b then c else d end

두번째 decode는
case when a=b then c when a=d then e end

반응형