- 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
How to use MySQL decimal?
MySQL decimal data type can be used to store the exact numerical value. The syntax of DECIMAL data type.
yourColumnName Decimal(integerValue,intgerValue);
Example of DECIMAL data type.
mysql> create table EmployeeInformation -> ( -> EmpId int auto_increment primary key, -> EmpName varchar(200), -> EmpSalary DECIMAL(6.2) -> ); Query OK, 0 rows affected (0.54 sec)
Whenever we insert a value in “EmpSalary” column greater than 6 digits, it raise an error. The error is as follows −
mysql> insert into EmployeeInformation(EmpName,EmpSalary) values('John',6999999.50); ERROR 1264 (22003): Out of range value for column 'EmpSalary' at row 1
Inserting value in “EmpSalary” column with exact number of digits.
mysql> insert into EmployeeInformation(EmpName,EmpSalary) values('John',6999.50); Query OK, 1 row affected, 1 warning (0.15 sec) mysql> insert into EmployeeInformation(EmpName,EmpSalary) values('John',69999.50); Query OK, 1 row affected, 1 warning (0.20 sec)
To display all records.
mysql> select *from EmployeeInformation;
The following is the output.
+-------+---------+-----------+ | EmpId | EmpName | EmpSalary | +-------+---------+-----------+ | 1 | John | 7000 | | 2 | John | 70000 | +-------+---------+-----------+ 2 rows in set (0.00 sec)
- Related Articles
- How to store decimal in MySQL?
- How to insert DECIMAL into MySQL database?
- MySQL - CAST DECIMAL to INT?
- How to format number to 2 decimal places in MySQL?
- How to use Coalesce in MySQL?
- MySQL SUM function to add decimal values
- How to store the PayPal decimal amount in the MySQL database?
- How to get number located at 2 places before decimal point MySQL?
- How to use Straight Join in MySQL?
- How to use TIME type in MySQL?
- How to use % wildcard correctly in MySQL?
- How to use SELF JOIN in MySQL?
- How do I format a number as decimal to store it in MySQL?
- How to specify Decimal Precision and scale number in MySQL database using PHPMyAdmin?
- How do I update the decimal column to allow more digits in MySQL?

Advertisements