0

我有一个字符串,其中存储了大量数据。字符串如下所示:

DUTBOARD|A1DT25522;LOADBOARD|A2LB1896;PROBECARD|A4PC40257;PROGRAMNAME|DS2781;TESTOPTION|POSTBAKE;TESTTEMP|ROOM TEMP

我需要的是仅显示 Dutboard、Loadboard、Probecard、Cable 和 Motherboard 及其值。我打算使用 REGEXP_SUBSTR 然后将它们全部连接起来。这是我到目前为止所拥有的:

SELECT  'DUTBOARD|A1DT25522;LOADBOARD|A2LB1896;PROBECARD|A4PC40257;PROGRAMNAME|DS2781;TESTOPTION|POSTBAKE;TESTTEMP|ROOM TEMP' hw
  , regexp_substr('DUTBOARD|A1DT25522;LOADBOARD|A2LB1896;PROBECARD|A4PC40257;PROGRAMNAME|DS2781;TESTOPTION|POSTBAKE;TESTTEMP|ROOM TEMP', '(;|^)LOADBOARD\|(.*)(;|$)', 1, 1, '', 2) lol
FROM dual

非常感谢。

4

2 回答 2

0
WITH tab AS
     (SELECT     REGEXP_SUBSTR
                    ('DUTBOARD|A1DT25522;LOADBOARD|A2LB1896;PROBECARD|A4PC40257;PROGRAMNAME|DS2781;TESTOPTION|POSTBAKE;TESTTEMP|ROOM TEMP',
                     '[^;]+',
                     1,
                     LEVEL
                    ) regular_expression
            FROM DUAL
      CONNECT BY REGEXP_SUBSTR
                    ('DUTBOARD|A1DT25522;LOADBOARD|A2LB1896;PROBECARD|A4PC40257;PROGRAMNAME|DS2781;TESTOPTION|POSTBAKE;TESTTEMP|ROOM TEMP',
                     '[^;]+',
                     1,
                     LEVEL
                    ) IS NOT NULL)
SELECT REGEXP_SUBSTR (regular_expression, '[^|]+'),
       REGEXP_REPLACE (regular_expression, '.*\|([^ ]*).*', '\1')
  FROM tab

输出

http://www.sqlfiddle.com/#!4/d41d8/17310

于 2013-09-16T05:51:59.930 回答
0

因此,您希望提取这些特定字段,然后重新连接数据?如果您不是特别喜欢 REGEX_SUBSTR,这对您有用吗?

WITH TestStringsCTE AS (
  SELECT REGEXP_REPLACE(str, '.*DUTBOARD\|([^;|]+);.*', '\1') AS DUTBOARD
    ,REGEXP_REPLACE(str, '.*LOADBOARD\|([^;|]+);.*', '\1') AS LOADBOARD
    ,REGEXP_REPLACE(str, '.*PROBECARD\|([^;|]+);.*', '\1') AS PROBECARD
  FROM TestStrings)

SELECT ('DUTBOARD'||'|'||DUTBOARD||';'
        ||'LOADBOARD'||'|'||LOADBOARD||';'
        ||'PROBECARD'||'|'||PROBECARD||';') AS str FROM TestStringsCTE;

http://sqlfiddle.com/#!4/19ee7/15

于 2013-09-19T20:57:22.640 回答