SQL中如何得到一个数字的小数位数?

[复制链接]
查看11 | 回复3 | 2005-10-30 17:05:33 | 显示全部楼层 |阅读模式
SQL中如何得到一个数字的小数位数?
比如100.235的小数位数是3,100.9的小数位数是1
回复

使用道具 举报

千问 | 2005-10-30 17:05:33 | 显示全部楼层
11:20:38 SQL> select length(100)-decode(instr(to_char(100),'.'),0,length(100),in
str(to_char(100),'.')) from dual;
LENGTH(100)-DECODE(INSTR(TO_CHAR(100),'.'),0,LENGTH(100),INSTR(TO_CHAR(100),'.')
)
--------------------------------------------------------------------------------
-
0
已用时间:00: 00: 00.15
11:20:55 SQL> select length(100.235)-decode(instr(to_char(100.235),'.'),0,length
(100.235),instr(to_char(100.235),'.')) from dual;
LENGTH(100.235)-DECODE(INSTR(TO_CHAR(100.235),'.'),0,LENGTH(100.235),INSTR(TO_CH
AR(100.235),'.'))
--------------------------------------------------------------------------------
-----------------

3
已用时间:00: 00: 00.00
11:21:12 SQL> select length(100.9)-decode(instr(to_char(100.9),'.'),0,length(100
.9),instr(to_char(100.9),'.')) from dual;
LENGTH(100.9)-DECODE(INSTR(TO_CHAR(100.9),'.'),0,LENGTH(100.9),INSTR(TO_CHAR(100
.9),'.'))
--------------------------------------------------------------------------------
---------
1
已用时间:00: 00: 00.00
回复

使用道具 举报

千问 | 2005-10-30 17:05:33 | 显示全部楼层
多谢!
回复

使用道具 举报

千问 | 2005-10-30 17:05:33 | 显示全部楼层
select length(-1234.2567)-length(trunc(-1234.2567))-1 from dual
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行