- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
MySQL query to copy IP address from varchar column to integer in the same table?
For this, you can use INET_ATON(). Let us first create a −
mysql> create table DemoTable1404 -> ( -> IpAddress varchar(40) -> ); Query OK, 0 rows affected (1.02 sec)
Insert some records in the table using insert −
mysql> insert into DemoTable1404 values('192.168.120.0'); Query OK, 1 row affected (0.43 sec) mysql> insert into DemoTable1404 values('192.168.120.20'); Query OK, 1 row affected (0.60 sec) mysql> insert into DemoTable1404 values('224.0.0.0'); Query OK, 1 row affected (0.42 sec)
Display all records from the table using select −
mysql> select * from DemoTable1404;
This will produce the following output −
+----------------+ | IpAddress | +----------------+ | 192.168.120.0 | | 192.168.120.20 | | 224.0.0.0 | +----------------+ 3 rows in set (0.00 sec)
Following is the query to copy IP address from varchar column to integer in the same −
mysql> select inet_aton(IpAddress) from DemoTable1404;
This will produce the following output −
+----------------------+ | inet_aton(IpAddress) | +----------------------+ | 3232266240 | | 3232266260 | | 3758096384 | +----------------------+ 3 rows in set (0.00 sec)
No, let us prove that the conversion was successful or not −
mysql> select inet_ntoa('3232266240');
This will produce the following output −
+-------------------------+ | inet_ntoa('3232266240') | +-------------------------+ | 192.168.120.0 | +-------------------------+ 1 row in set (0.27 sec)
- Related Articles
- Alter a table column from VARCHAR to NULL in MySQL
- Order a column in MySQL with IP Address records?
- Copy from one column to another (different tables same database) in MySQL?
- MySQL query to copy records from one table to another with different columns
- How to alter a MySQL Column from varchar(30) to varchar(100)?
- MySQL query to replace backslash from a varchar column with preceding backslash string values
- MySQL query to select average from distinct column of table?
- Convert varchar to unsigned integer in MySQL
- Which MySQL datatype to used to store an IP address?
- MySQL query to get first two highest column values from a table?
- Copy column values from one table into another matching IDs in MySQL
- How to copy rows from one table to another in MySQL?
- MySQL query to get max id from varchar type and the values in numeric?
- How to select only non - numeric values from varchar column in MySQL?
- How to get the ip address in C#?

Advertisements