0

Any source for an Oracle function that will convert from raw numbers to IPV4 or IPV6?

CREATE or replace FUNCTION inttoip(ip_address IN INTEGER) RETURN VARCHAR2 IS
v8 varchar2(8);
ip_str varchar2(16) default null;
BEGIN
if ip_address is not null then
-- 1. convert the integer into hexadecimal representation
v8 := LPAD(TO_CHAR(ip_address, 'FMXXXXXXXX'),8,'0');
-- 2. convert each XX portion back into decimal
ip_str := to_number(substr(v8,1,2),'XX')
|| '.' || to_number(substr(v8,3,2),'XX')
|| '.' || to_number(substr(v8,5,2),'XX')
|| '.' || to_number(substr(v8,7,2),'XX');
end if;
return ip_str;
END inttoip;
Brad Larson
  • 170,088
  • 45
  • 397
  • 571
  • Hi and welcome to Stack Overflow. You're asking someone to just provide you the code, it would be better if you could show [what you have attempted](http://mattgemmell.com/2008/12/08/what-have-you-tried/). This is a question and answer site where people give their time up, for free, to help you. It's polite to put some effort in first. – Ben Nov 02 '12 at 17:06
  • Secondly, `raw` is a data-type, it has special meaning in Oracle, and is not associated with "numbers". Your question doesn't really make much sense, therefore. Do you mean you have a number, that you would like to convert to and IP address? What do the numbers look like? – Ben Nov 02 '12 at 17:07
  • :) @Ben thanks for your help, appreciate it – Eee-boo-nah Eee-boo-nah Nov 02 '12 at 18:13
  • 1
    So what's your question? Your function seems to do what you want - converts `3725989378` to `222.22.22.2` (the reverse of what [this site](http://www.csgnetwork.com/ipaddconv.html) shows for example). – Alex Poole Nov 02 '12 at 19:22
  • Although it looks like you got that code from [this answer](http://stackoverflow.com/a/1085622/266304), with just an additional `if` and storing the value in a local variable... – Alex Poole Nov 02 '12 at 19:24
  • 1
    Please don't replace your question with something entirely different. If you have a new question to ask, do so as a separate question. – Brad Larson Nov 08 '12 at 16:05

0 Answers0