Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.misc -> Re: Trimming IP Addresses
jhulst wrote:
> Hello,
> I am looking for a function that will allow me to trim off the right
> octet of an ip address. ie. go from 192.168.1.255 to 192.168.1
> I tried using a rtrim function using a wildcard such as
> rtrim(ipaddress, '.%') but it doesn't give me anything. Any help or
> advice would be much appreciated.
>
> Thanks,
> Josh
In 10g and later, you can use REGEXP_SUBSTR():
RTRIM(REGEXP_SUBSTR(:ip_address,'^([0-9]\.){3}'),'.')
In all releases you can use a combination of INSTR() and SUBSTR():
SUBSTR(:ip_address,1,INSTR(:ip_address,'.'-1)-1)
Hth,
Vladimir M. Zakharychev
N-Networks, makers of Dynamic PSP(tm)
http://www.dynamicpsp.com
Received on Thu Jun 08 2006 - 10:59:38 CDT