col "前ゼロを削除" for a16
--■■■to_number関数を使う方法■■■
select IPAddress,
to_char(to_number(
substr(IPAddress,1,instr(IPAddress,'.')-1))) || '.' ||
to_char(to_number(
substr(IPAddress,instr(IPAddress,'.')+1,
instr(IPAddress,'.',1,2)-instr(IPAddress,'.')-1))) || '.' ||
to_char(to_number(
substr(IPAddress,instr(IPAddress,'.',1,2)+1,
instr(IPAddress,'.',1,3)-instr(IPAddress,'.',1,2)-1))) || '.' ||
to_char(to_number(
substr(IPAddress,instr(IPAddress,'.',1,3)+1))) as "前ゼロを削除"
from IP;
--■■■正規表現を使う方法1■■■
select IPAddress,
to_char(to_number(RegExp_Replace(IPAddress,'^([^.]+).*$','\1'))) || '.' ||
to_char(to_number(RegExp_Replace(IPAddress,'^[^.]+\.([^.]+).*$','\1'))) || '.' ||
to_char(to_number(RegExp_Replace(IPAddress,'^([^.]+\.){2}([^.]+).*$','\2'))) || '.' ||
to_char(to_number(RegExp_Replace(IPAddress,'^([^.]+\.){3}([^.]+).*$','\2'))) as "前ゼロを削除"
from IP;
--■■■正規表現を使う方法2■■■
select IPAddress,
RegExp_Replace(IPAddress,'(^|\.)0+([0-9]+)','\1\2') as "前ゼロを削除"
from IP;