sql like子句有很多值

时间:2012-10-18 19:43:23

标签: sql oracle sql-like

我的桌子上有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')

3 个答案:

答案 0 :(得分:2)

您可以尝试regexp_like功能

答案 1 :(得分:0)

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

答案 2 :(得分: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%')