
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
How to 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)
- Related Articles
- How to insert data into a MySQL database with Java?
- How to get the id after INSERT into MySQL database using Python?
- Java application to insert null value into a MySQL database?
- 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?
- How to insert a Python tuple in a MySQL database?
- How to insert raw data in MySQL database in Laravel?
- How to insert new documents into a MongoDB collection in your database?
- Change value of decimal(19, 2) when inserting into the database in MySQL?
- Insert NULL value into database field with char(2) as type in MySQL?
- Insert current date to the database in MySQL?
- How to insert NULL into char(1) in MySQL?
- How to Insert custom date into MySQL timestamp field?
- How to store the PayPal decimal amount in the MySQL database?

Advertisements