- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to insert DECIMAL into MySQL database?
To insert decimal into MySQL, you can use DECIMAL() function from MySQL. The syntax is as follows
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)
- How to insert data into a MySQL database with Java?
- Java application to insert null value into a MySQL database?
- How to get the id after INSERT into MySQL database using Python?
- How do we insert/store a file into MySQL database using JDBC?
- How do I get the id after INSERT into MySQL database in Python?
- How to insert/store JSON array into a database using JDBC?
- Change value of decimal(19, 2) when inserting into the database in MySQL?
- How to insert new documents into a MongoDB collection in your database?
- How to Insert custom date into MySQL timestamp field?
- How to insert NULL into char(1) in MySQL?
- Insert NULL value into database field with char(2) as type in MySQL?
- How to insert a Python tuple in a MySQL database?
- Insert current date to the database in MySQL?
- How to store the PayPal decimal amount in the MySQL database?
- Insert JSON into a MySQL table?