MySQL中货币的最佳数据类型是什么?
MySQL中货币的最佳数据类型是DECIMAL。DECIMAL数据类型的语法如下-
DECIMAL(TotalDigit,NumberOfDigitAfterDecimalPoint);
为了理解上述语法,让我们创建一个表。创建表的查询如下-
mysql> create table CurrenciesDemo -> ( -> TotalPrice DECIMAL(10,2) -> );
使用insert命令在表中插入一些记录。查询如下-
mysql> insert into CurrenciesDemo values(1647575.67); mysql> insert into CurrenciesDemo values(1647575); mysql> insert into CurrenciesDemo values(99599596); mysql> insert into CurrenciesDemo values(1986.50); mysql> insert into CurrenciesDemo values(99999999.90);
使用select语句显示表中的所有记录。查询如下-
mysql> select *from CurrenciesDemo;
以下是输出-
+-------------+ | TotalPrice | +-------------+ | 1647575.67 | | 1647575.00 | | 99599596.00 | | 1986.50 | | 99999999.90 | +-------------+ 5 rows in set (0.00 sec)
以下是查询以显示所有上述价格,并带有前缀符号,例如dollar-
mysql> select concat('$',TotalPrice) as DollerSign from CurrenciesDemo;以下是输出-
+--------------+ | DollerSign | +--------------+ | $1647575.67 | | $1647575.00 | | $99599596.00 | | $1986.50 | | $99999999.90 | +--------------+ 5 rows in set (0.00 sec)
热门推荐
10 新年门口花束祝福语简短
11 盘锦结婚祝福语大全简短
12 父母生日祝福语 简短独特
13 家庭恩爱祝福语简短英文
14 高考俄语祝福语大全简短
15 虎年祝福语 诗句唯美简短
16 生日婚礼祝福语简短精辟
17 虎年喝酒拜年祝福语简短
18 教师闺蜜祝福语简短