我想比较下面的2个字符串
19.12.XX.11 = 19.12.YY.11
我尝试了下面的一个,但它只替换了第一个字符
select REGEXP_REPLACE('19.12.1.11' ,'.', 'x', 4, 4 )
from dual;
答案 0 :(得分:0)
Oracle安装程序:
CREATE TABLE ipaddresses ( addr1, addr2 ) AS
SELECT '19.12.0.11', '19.12.1.11' FROM DUAL;
<强>查询强>:
SELECT addr1,
addr2,
CASE TO_NUMBER( REGEXP_SUBSTR( addr1, '\d+', 1, 1 ) )
WHEN TO_NUMBER( REGEXP_SUBSTR( addr2, '\d+', 1, 1 ) )
THEN 'Match'
ELSE 'No Match'
END AS Byte1,
CASE TO_NUMBER( REGEXP_SUBSTR( addr1, '\d+', 1, 2 ) )
WHEN TO_NUMBER( REGEXP_SUBSTR( addr2, '\d+', 1, 2 ) )
THEN 'Match'
ELSE 'No Match'
END AS Byte2,
CASE TO_NUMBER( REGEXP_SUBSTR( addr1, '\d+', 1, 3 ) )
WHEN TO_NUMBER( REGEXP_SUBSTR( addr2, '\d+', 1, 3 ) )
THEN 'Match'
ELSE 'No Match'
END AS Byte3,
CASE TO_NUMBER( REGEXP_SUBSTR( addr1, '\d+', 1, 4 ) )
WHEN TO_NUMBER( REGEXP_SUBSTR( addr2, '\d+', 1, 4 ) )
THEN 'Match'
ELSE 'No Match'
END AS Byte4
FROM ipaddresses;
<强>输出强>:
ADDR1 ADDR2 BYTE1 BYTE2 BYTE3 BYTE4
---------- ---------- -------- -------- -------- --------
19.12.0.11 19.12.1.11 Match Match No Match Match