Open In App

INET_NTOA() function in MySQL

INET_NTOA() :

This function in MySQL takes the IPv4 address in network byte order and then it returns the address as a dotted-quad string representation. This function returns NULL if the input address is an invalid IPv4 address. 



Syntax :

INET_NTOA(expr)

Parameter : This function accepts only one parameter.



Returns : 

It returns a dotted-quad string representation of the given IPv4 address.

Example-1 :

Checking the equivalent dotted-quad string representation for the following address “17171712” with the help of INET_NTOA Function. As it is a valid IPv4 address we will get the result in a dotted string.

SELECT INET_NTOA(17171712)  
AS Address_In_DottedString ;

Output :

ADDRESS_IN_DOTTEDSTRING
1.6.5.0

Example-2 :

Checking the equivalent dotted-quad string representation for the following address “-121” with the help of INET_NTOA Function. As it is not a valid IPv4 address we will get NULL.

SELECT INET_NTOA(-121)  
AS Address_In_DottedString ;

Output :

ADDRESS_IN_DOTTEDSTRING
 NULL

Example -3 :

Checking the equivalent dotted-quad string representation for the following decimal number “171712.01223” with the help of INET_NTOA Function. 

SELECT INET_NTOA (171712.01223)  
AS Address_In_DottedString ;

Output :

ADDRESS_IN_DOTTEDSTRING
0.2.158.192

Example-4 :

Checking the equivalent dotted-quad string representation for the following binary number “101011001” with the help of INET_NTOA Function. 

SELECT INET_NTOA(b'101011001')  
AS Address_In_DottedString ;

Output :

ADDRESS_IN_DOTTEDSTRING
0.0.1.89
Article Tags :
SQL