如何將 DECIMAL 插入 MySQL 資料庫?
要將十進位制插入 MySQL,可使用 MySQL 中的 DECIMAL() 函式。語法如下
yourColumnName DECIMAL(TotalDigit,DigitAfterDecimalPoint);
為理解上述語法,讓我們建立一個表。建立表的查詢如下
mysql> create table DecimalInsert -> ( -> Id int, -> Name varchar(100), -> Amount DECIMAL(4,2) -> ); Query OK, 0 rows affected (0.65 sec)
使用插入命令插入十進位制值。查詢如下
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)
使用 select 語句顯示錶中的所有記錄。查詢如下
mysql> select *from DecimalInsert;
以下為輸出
+------+-------+--------+ | Id | Name | Amount | +------+-------+--------+ | 1 | John | 12.40 | | 2 | Carol | 12.34 | | 3 | Mike | 1.42 | +------+-------+--------+ 3 rows in set (0.00 sec)
廣告