
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Insert Decimal into MySQL Database
To insert decimal into MySQL, you can use DECIMAL() function from MySQL. The syntax is as follows
yourColumnName DECIMAL(TotalDigit,DigitAfterDecimalPoint);
To understand the above syntax, let us create a table. The query to create a table is as follows
mysql> create table DecimalInsert -> ( -> Id int, -> Name varchar(100), -> Amount DECIMAL(4,2) -> ); Query OK, 0 rows affected (0.65 sec)
Insert the decimal value using insert command. The query is as follows
mysql> insert into DecimalInsert values(1,'John',12.4); Query OK, 1 row affected (0.15 sec) mysql> insert into DecimalInsert values(2,'Carol',12.34); Query OK, 1 row affected (0.16 sec) mysql> insert into DecimalInsert values(3,'Mike',1.424); Query OK, 1 row affected, 1 warning (0.17 sec)
Display all records from the table using select statement. The query is as follows
mysql> select *from DecimalInsert;
The following is the output
+------+-------+--------+ | Id | Name | Amount | +------+-------+--------+ | 1 | John | 12.40 | | 2 | Carol | 12.34 | | 3 | Mike | 1.42 | +------+-------+--------+ 3 rows in set (0.00 sec)
Advertisements