如何使用MySQL decimal类型?
MySQL decimal数据类型用于存储精确的数值。DECIMAL数据类型的语法。
yourColumnName Decimal(integerValue,intgerValue);
DECIMAL数据类型的示例。
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)
每当我们向“EmpSalary”列中插入大于6位数字的值时,都会引发错误。错误如下所示−
mysql> insert into EmployeeInformation(EmpName,EmpSalary) values('John',6999999.50);
ERROR 1264 (22003): Out of range value for column 'EmpSalary' at row 1
在“EmpSalary”列中插入具有精确数字位数的值。
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)
显示所有记录。
mysql> select *from EmployeeInformation;
以下是输出结果。
+-------+---------+-----------+
| EmpId | EmpName | EmpSalary |
+-------+---------+-----------+
| 1 | John | 7000 |
| 2 | John | 70000 |
+-------+---------+-----------+
2 rows in set (0.00 sec)
阅读更多:MySQL 教程