--测试数据 create table temp(cip varchar2(100));insert into temp select '192.168.168.1' from dual union all select 'abc' from dual union all select 'abcfdasfd' from dual union all select '10.10.0.1' from dual; --执行查询 select * from temp where cip like '%.%.%.%' --输出结果 192.168.168.1 10.10.0.1
select * from temp2 where translate(replace( decode(instr(cip,':',1),0,cip,substr(cip,1,instr(cip,':',1)-1)),'.',''),'\1234567890','\') is null and cip like '%.%.%.%'
create table temp(cip varchar2(100));insert into temp
select '192.168.168.1' from dual union all
select 'abc' from dual union all
select 'abcfdasfd' from dual union all
select '10.10.0.1' from dual;
--执行查询
select * from temp where cip like '%.%.%.%'
--输出结果
192.168.168.1
10.10.0.1
TRANSLATE(string,from_str,to_str)
二、目的
返回将(所有出现的)from_str中的每个字符替换为to_str中的相应字符以后的string。TRANSLATE 是 REPLACE 所提供的功能的一个超集。如果 from_str 比 to_str 长,那么在 from_str 中而不在 to_str 中的额外字符将从 string 中被删除,因为它们没有相应的替换字符。to_str 不能为空。Oracle 将空字符串解释为 NULL,并且如果TRANSLATE 中的任何参数为NULL,那么结果也是 NULL。
三、允许使用的位置
过程性语句和SQL语句。
四、示例
SELECT TRANSLATE('abcdefghij','abcdef','123456') FROM dual;
TRANSLATE (
--------------
123456ghij
SELECT TRANSLATE('abcdefghij','abcdefghij','123456') FROM dual;
TRANSL
----------
123456
translate(replace( decode(instr(cip,':',1),0,cip,substr(cip,1,instr(cip,':',1)-1)),'.',''),'\1234567890','\') is null
and cip like '%.%.%.%'