4
select status_a,status_b from test 

オラクルのデコード関数 a を使用して以下の値をデコードする方法status_astatus_bおよび status_a または status_b の値のいずれかが null の場合。

if  status_a='Y' and status_b='Y' then 'Y'

if  status_a='Y' and status_b='N' then 'N'

if  status_a='N' and status_b='Y' then 'N'

if  status_a='N' and status_b='N' then 'N'

よろしく、

チャトゥハラ

4

3 に答える 3

7

なぜ使用したいのDECODEですか? CASEはるかに適しているように思えます

CASE WHEN status_a = 'Y' and status_b = 'Y' THEN 'Y'
     WHEN status_a = 'Y' and status_b = 'N' THEN 'N'
     WHEN status_a = 'N' and status_b = 'Y' THEN 'N'
     WHEN status_a = 'N' and status_b = 'N' THEN 'N'
  END

もちろん、投稿したロジックは意味がないようです。status_a = 'Y' or status_b = 'Y'TRUE に評価されたときに FALSE に評価される唯一の方法status_a = 'Y' or status_b = 'N'は、 if status_a = 'N'andstatus_b = 'N'です。しかし、それは 3 番目と 4 番目の分岐に決して到達しないことを意味します。andではなく意味があればor、ロジックは理にかなっています。しかし、その場合、次のように単純化できます

CASE WHEN status_a = 'Y' and status_b = 'Y' THEN 'Y'
     ELSE 'N'
  END
于 2013-09-05T21:38:55.703 に答える
2

OR ではなく AND を意味する場合、これはデコードを使用して実行できます。

decode(status_a,'Y',
       decode(status_b,'Y','Y','N'),
       'N')

または、これは次のように簡略化できます。

decode(status_a||status_b,'YY','Y','N')
于 2013-09-05T21:40:14.480 に答える