
- 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
Change value of decimal(19, 2) when inserting into the database in MySQL?
To store the exact real value, you need to use truncate() with 2 decimal point. Let us create a table −
Following is the query to create a table.
mysql> create table demo59 −> ( −> price decimal(19,2) −> ); Query OK, 0 rows affected (1.12 sec)
Insert some records into the table with the help of insert command −
mysql> insert into demo59 values(truncate(15.346, 2)); Query OK, 1 row affected (0.14 sec) mysql> insert into demo59 values(truncate(20.379, 2)); Query OK, 1 row affected (0.72 sec) mysql> insert into demo59 values(truncate(25.555, 2)); Query OK, 1 row affected (0.16 sec) mysql> insert into demo59 values(truncate(100.456, 2)); Query OK, 1 row affected (0.21 sec)
Display records from the table using select statement −
mysql> select *from demo59;
This will produce the following output −
+--------+ | price | +--------+ | 15.34 | | 20.37 | | 25.55 | | 100.45 | +--------+ 4 rows in set (0.00 sec)
- Related Articles
- How to insert DECIMAL into MySQL database?
- Can we skip column when inserting into MySQL?
- Inserting Array list into HANA database
- Display the warning message when a FLOAT value is inserted into DECIMAL in MySQL?
- Insert NULL value into database field with char(2) as type in MySQL?
- Inserting random numbers into a table in MySQL?
- Java application to insert null value into a MySQL database?
- How to store the PayPal decimal amount in the MySQL database?
- Inserting records into a MySQL table using PreparedStatement in Java?
- How can we change the default MySQL database to the given database?
- Inserting data into a new column of an already existing table in MySQL?
- Change the decimal point of every value in an R data frame column.
- Convert $\frac{5}{2}$ into decimal.
- Inserting multiple parameter values into a single column with MySQL?
- Change max_heap_table_size value in MySQL?

Advertisements