You can use simple string functions ( INSTR and SUBSTR ), which are much faster than regular expressions:
SQL Fiddle
Oracle 11g R2 schema setup :
CREATE TABLE sample_data ( ip_address ) AS SELECT '10.20.30.40' FROM DUAL
Request 1 :
SELECT TO_NUMBER( SUBSTR( ip_address, 1, first_sep - 1 ) ) AS ClassA, TO_NUMBER( SUBSTR( ip_address, first_sep + 1, second_sep - first_sep ) ) AS ClassB, TO_NUMBER( SUBSTR( ip_address, second_sep + 1, third_sep - second_sep ) ) AS ClassC, TO_NUMBER( SUBSTR( ip_address, third_sep + 1 ) ) AS ClassD FROM ( SELECT ip_address, INSTR( ip_address, '.', 1, 1 ) AS first_sep, INSTR( ip_address, '.', 1, 2 ) AS second_sep, INSTR( ip_address, '.', 1, 3 ) AS third_sep FROM sample_data )
Results :
| CLASSA | CLASSB | CLASSC | CLASSD | |--------|--------|--------|--------| | 10 | 20 | 30 | 40 |
source share