decimal(m,n)

1.不同数据库中的区别 

Hive的decimal类型类似Oracle,decimal(m,n)表示数字总长度为m位,小数位为n位,那么整数位就只有m-n位。

drop table if exists test_table_decimal;
create table if not exists test_table_decimal
(
    businesssum decimal(4,2) COMMENT '金额',
    stat_dt string coment'日期'
) stored as parquet;

insert into test_table_decimalvalues(1000.00,'20230801');
insert into test_table_decimalvalues(100.00,'20230802');
insert into test_table_decimalvalues(10.00,'20230803');
insert into test_table_decimalvalues(1.00,'20230804');
insert into test_table_decimalvalues(1000.0,'20230805');
insert into test_table_decimalvalues(100.0,'20230806');
insert into test_table_decimalvalues(10.0,'20230807');
insert into test_table_decimalvalues(1.0,'20230808');

select * from test_table_decimal order by stat_dt;

 

MySql的decimal类型,decimal(m,n)表示整数位为m位,小数位为n位。

如果你在Hive中使用的时候发现字段长度不够,Hive在处理数值字段的时候会直接置该字段值为NULL,不会将它截去。

2.查询decimal类型数据字段有效数值长度
select 
,max(locate('.',cast(decimal_col as string)) -1)
,max(length(regexp_replace(rtrim(regexp_replace(cast(decimal_col as string),'0',' ')),' ','0'))
     - locate('.',cast(decimal_col as string)) 
     )
from table_name;
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值