0

我需要拆分消息:

 500 Oracle Parkway.Redwood Shores.*.=13

现在我对 Substr1/2/4 有了一些可行的解决方案

  SELECT '500 Oracle Parkway.Redwood Shores.*.=13' string1,
  REGEXP_SUBSTR('500 Oracle Parkway.Redwood Shores.*.=13','.[^.]+') 
  "SUBSTR1" ,
  replace(REGEXP_SUBSTR('500 Oracle Parkway.Redwood Shores.*.=13','[$.]+
  [^.]+'),'.',null) "SUBSTR2" ,
  REGEXP_SUBSTR('500 Oracle Parkway.Redwood Shores.*.=13','[$.]+.[$.]+[^.]') 
  "SUBSTR3" ,
  REGEXP_SUBSTR('500 Oracle Parkway.Redwood Shores.*.=13','[^=]+$') 
  "SUBSTR4" 
  FROM DUAL;

但是 Substr3 包含'='。我希望至少有 '.*.' 或者 ' * '

你能否给我一个提示如何在正则表达式中“排除”任何字符(例如'=')?

任何帮助深表感谢!

谢谢

已解决见 SUBSTR3.1

      SELECT
     '500 Oracle Parkway.Redwood Shores.*.=13' string1,
      REGEXP_SUBSTR('500 Oracle Parkway.Redwood Shores.*.=13','.[^.]+') 
      "SUBSTR1" ,
      replace(REGEXP_SUBSTR('500 Oracle Parkway.Redwood Shores.*.=13','[$.]+
      [^.]+'),'.',null) "SUBSTR2" ,
      REGEXP_SUBSTR('500 Oracle Parkway.Redwood Shores.*.=13','[$.]+.[$.]+
      [^.]') "SUBSTR3" ,
      REGEXP_SUBSTR('500 Oracle Parkway.Redwood Shores.*.=13','[^.]+',1,3) 
      "SUBSTR3.1" ,
      REGEXP_SUBSTR('500 Oracle Parkway.Redwood Shores.*.=13','[^=]+$') 
      "SUBSTR4" 
      FROM DUAL;
4

2 回答 2

2

非常尊重 Alex Poole,'[^.]+'如果列表中的一个元素丢失,格式的正则表达式就会失败。它将默默地返回不正确的数据。请改用此表格。请注意,我从第一个示例中删除了城市。尝试一下,您可能会感到惊讶:

with t (str) as (
  select '500 Oracle Parkway..*.=13' from dual union 
  select 'One Microsoft Way.Redmond.Washington.=27' from dual
)
select str,
  regexp_substr(str, '(.*?)(\.|$)', 1, 1, NULL, 1) as substr1,
  regexp_substr(str, '(.*?)(\.|$)', 1, 2, NULL, 1) as substr2,
  regexp_substr(str, '(.*?)(\.|$)', 1, 3, NULL, 1) as substr3,
  ltrim(regexp_substr(str, '(.*?)(\.|$)', 1, 4, NULL, 1), '=') as substr4
from t;

有关更多信息,请参见此处:将逗号分隔值拆分为 Oracle 中的列

于 2017-05-10T14:01:33.897 回答
1

看起来您正在尝试根据句点对源字符串进行标记,并且它们(可能)从第四个标记中删除了前导等号。您用于“substring3.1”的解决方案可用于所有这些:

with t (str) as (
  select '500 Oracle Parkway.Redwood Shores.*.=13' from dual
  union all select 'One Microsoft Way.Redmond.Washington.=27' from dual
)
select str,
  regexp_substr(str, '[^.]+', 1, 1) as substr1,
  regexp_substr(str, '[^.]+', 1, 2) as substr2,
  regexp_substr(str, '[^.]+', 1, 3) as substr3,
  ltrim(regexp_substr(str, '[^.]+', 1, 4), '=') as substr4
from t;

STR                                      SUBSTR1              SUBSTR2              SUBSTR3    SUBSTR4
---------------------------------------- -------------------- -------------------- ---------- -------
500 Oracle Parkway.Redwood Shores.*.=13  500 Oracle Parkway   Redwood Shores       *          13     
One Microsoft Way.Redmond.Washington.=27 One Microsoft Way    Redmond              Washington 27     
于 2017-05-10T10:06:00.740 回答