4

我的表中有 4 列。现在,由于这更像是一项数据清理任务,所以我对性能并不是那么特别。但我仍然想知道可能的选择。

看下面的查询:

SELECT * FROM dsopi_person_addr_rule ADDR WHERE 
addr.src_address_line1 LIKE '%DEP%' 
OR addr.src_address_line2 LIKE '%DEP%'
OR addr.src_address_line3 LIKE '%DEP%'
OR addr.src_address_line4 LIKE '%DEP%';

与 DEP 类似,我还有 10 场比赛。我需要为所有 4 个地址行重复每个匹配项。有更好的方法吗?我个人讨厌一次又一次地写作。

**更新:以下是答案

SELECT *
FROM dsopi_person_addr_rule ADDR
WHERE regexp_like (UPPER(addr.src_address_line1),      'DEP|DPT$|ABT|DIP.|DIPART|AFDEL|AVDEL|AVD.|DIV|PGRD|PGP|PPG')
4

3 回答 3

2

你可以试试regexp_like函数

于 2012-10-18T19:54:32.843 回答
0

您可以尝试编写一个存储过程,将“DEP”部分作为参数输入。然后只需连接所有存储过程调用的结果。

于 2012-10-18T19:47:19.947 回答
0
CREATE VIEW VW_dsopi_person_addr_rule
AS
  SELECT Primary_key
       , src_address_line1 AS src_address_line
    FROM dsopi_person_addr_rule
   UNION
  SELECT Primary_key
       , src_address_line2
    FROM dsopi_person_addr_rule
   UNION
  SELECT Primary_key
       , src_address_line3
    FROM dsopi_person_addr_rule
  SELECT Primary_key
       , src_address_line4
    FROM dsopi_person_addr_rule

DELETE FROM VW_dsopi_person_addr_rule
  WHERE Primary_key in (SELECT Primary_key
                          FROM VW_dsopi_person_addr_rule
                         WHERE src_address_line like '%DEP%)

DELETE D1 FROM VW_dsopi_person_addr_rule D1
  WHERE EXISTS (SELECT 1
                  FROM VW_dsopi_person_addr_rule V1
                 WHERE V1.Primary_key_value1 = D1.Primary_key_value1
                   AND V1.Primary_key_value2 = D1.Primary_key_value2
                   AND V1.src_address_line like '%DEP%')
于 2012-10-18T19:55:34.063 回答