

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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
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 Questions & Answers
- 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?
- MySQL SUM function to add decimal values
- How to use Coalesce in MySQL?
- How to store the PayPal decimal amount in the MySQL database?
- Display 3 decimal places in MySQL?
- Use decimal in where clause in SAP ABAP
- How to Convert Binary to Decimal?
- How to Convert Decimal to Binary?
- How to Convert Decimal to Octal?
- How to Convert Decimal to Hexadecimal?
- How to Convert Hexadecimal to Decimal?
- How to get number located at 2 places before decimal point MySQL?
Advertisements