2

以下は私の質問です:

UPDATE DSOPI_PERSON_ADDR_RULE ADDR
SET ADDR.DEPT_NAME =
  CASE
    WHEN regexp_like (UPPER(addr.src_address_line1),     'DEP|DPT$|ABT|DIP.|DIPART|AFDEL|AVDEL|AVD.|DIV|PGRD|PGP|PPG')
    AND ADDR.ORG_NAME IS NOT NULL
    THEN ADDR.SRC_ADDRESS_LINE1
    WHEN regexp_like (UPPER(addr.src_address_line2), 'DEP|DPT$|ABT|DIP.|DIPART|AFDEL|AVDEL|AVD.|DIV|PGRD|PGP|PPG')
    AND ADDR.ORG_NAME IS NOT NULL
    THEN ADDR.SRC_ADDRESS_LINE2
    WHEN regexp_like (UPPER(addr.src_address_line3), 'DEP|DPT$|ABT|DIP.|DIPART|AFDEL|AVDEL|AVD.|DIV|PGRD|PGP|PPG')
    AND ADDR.ORG_NAME IS NOT NULL
    THEN ADDR.SRC_ADDRESS_LINE3
    WHEN regexp_like (UPPER(addr.src_address_line4), 'DEP|DPT$|ABT|DIP.|DIPART|AFDEL|AVDEL|AVD.|DIV|PGRD|PGP|PPG')
    AND ADDR.ORG_NAME IS NOT NULL
    THEN ADDR.SRC_ADDRESS_LINE4
    ELSE NULL
 END;

私がやりたいのは、ケース条件が真の場合、それぞれのアドレス行をNULLにしたいということです。このコードでそれを達成する方法はありますか?

4

2 に答える 2

1

したがって、最初のWHEN条件がtrueの場合、src_address_line1をNULLに設定しますか?この場合、私はこれを行います:

UPDATE DSOPI_PERSON_ADDR_RULE ADDR

SET 
addr.src_address_line1 = 
CASE WHEN regexp_like (UPPER(addr.src_address_line1), 'DEP|DPT$|ABT|DIP.|DIPART|AFDEL|AVDEL|AVD.|DIV|PGRD|PGP|PPG') 
AND ADDR.ORG_NAME IS NOT NULL 
THEN NULL ELSE addr.src_address_line1 END, 

addr.src_address_line2 = 
CASE WHEN regexp_like (UPPER(addr.src_address_line2), 'DEP|DPT$|ABT|DIP.|DIPART|AFDEL|AVDEL|AVD.|DIV|PGRD|PGP|PPG') 
AND ADDR.ORG_NAME IS NOT NULL 
THEN NULL ELSE addr.src_address_line2 END, 

addr.src_address_line3 = 
CASE WHEN regexp_like (UPPER(addr.src_address_line3), 'DEP|DPT$|ABT|DIP.|DIPART|AFDEL|AVDEL|AVD.|DIV|PGRD|PGP|PPG') 
AND ADDR.ORG_NAME IS NOT NULL 
THEN NULL ELSE addr.src_address_line3 END, 

addr.src_address_line4 = 
CASE WHEN regexp_like (UPPER(addr.src_address_line4), 'DEP|DPT$|ABT|DIP.|DIPART|AFDEL|AVDEL|AVD.|DIV|PGRD|PGP|PPG') 
AND ADDR.ORG_NAME IS NOT NULL 
THEN NULL ELSE addr.src_address_line4 END;  
于 2012-10-19T05:25:34.953 に答える
1

CASE必要なオプションの1つは、アドレスフィールドごとにステートメントを追加することです。

コードは複製されますが、これにより、条件が満たされたときにアドレス行をnullに設定できます。

UPDATE DSOPI_PERSON_ADDR_RULE ADDR
SET ADDR.DEPT_NAME =
   CASE
      WHEN regexp_like (UPPER(addr.src_address_line1),
         'DEP|DPT$|ABT|DIP.|DIPART|AFDEL|AVDEL|AVD.|DIV|PGRD|PGP|PPG')
         AND ADDR.ORG_NAME IS NOT NULL
         THEN ADDR.SRC_ADDRESS_LINE1
      WHEN regexp_like (UPPER(addr.src_address_line2), 
         'DEP|DPT$|ABT|DIP.|DIPART|AFDEL|AVDEL|AVD.|DIV|PGRD|PGP|PPG')
         AND ADDR.ORG_NAME IS NOT NULL
         THEN ADDR.SRC_ADDRESS_LINE2
      WHEN regexp_like (UPPER(addr.src_address_line3), 
         'DEP|DPT$|ABT|DIP.|DIPART|AFDEL|AVDEL|AVD.|DIV|PGRD|PGP|PPG')
         AND ADDR.ORG_NAME IS NOT NULL
         THEN ADDR.SRC_ADDRESS_LINE3
      WHEN regexp_like (UPPER(addr.src_address_line4), 
         'DEP|DPT$|ABT|DIP.|DIPART|AFDEL|AVDEL|AVD.|DIV|PGRD|PGP|PPG')
         AND ADDR.ORG_NAME IS NOT NULL
         THEN ADDR.SRC_ADDRESS_LINE4
      ELSE NULL
   END
   , ADDR.SRC_Address_Line1 =
        CASE
           WHEN regexp_like (UPPER(addr.src_address_line1),     
              'DEP|DPT$|ABT|DIP.|DIPART|AFDEL|AVDEL|AVD.|DIV|PGRD|PGP|PPG')
              AND ADDR.ORG_NAME IS NOT NULL
              THEN NULL
           ELSE ADDR.SRC_Address_Line1
        END
   , ADDR.SRC_Address_Line2 =
        CASE
           WHEN regexp_like (UPPER(addr.src_address_line2),     
              'DEP|DPT$|ABT|DIP.|DIPART|AFDEL|AVDEL|AVD.|DIV|PGRD|PGP|PPG')
              AND ADDR.ORG_NAME IS NOT NULL
              THEN NULL
           ELSE ADDR.SRC_Address_Line2
        END
   , ADDR.SRC_Address_Line3 =
        CASE
           WHEN regexp_like (UPPER(addr.src_address_line3),      
              'DEP|DPT$|ABT|DIP.|DIPART|AFDEL|AVDEL|AVD.|DIV|PGRD|PGP|PPG')
              AND ADDR.ORG_NAME IS NOT NULL
              THEN NULL
           ELSE ADDR.SRC_Address_Line3
        END
   , ADDR.SRC_Address_Line4 =
        CASE
           WHEN regexp_like (UPPER(addr.src_address_line4),     
              'DEP|DPT$|ABT|DIP.|DIPART|AFDEL|AVDEL|AVD.|DIV|PGRD|PGP|PPG')
              AND ADDR.ORG_NAME IS NOT NULL
              THEN NULL
           ELSE ADDR.SRC_Address_Line4
        END;
于 2012-10-19T05:25:43.760 に答える