Oracle显示号码
我们需要采用一些非常大的数字,并以这种缩写的方式显示它们:
2113546998.37 --> 21.37B
15481063.31 --> 15.31M
依此类推。我认为甲骨文没有这样做的方法。希望提供一些帮助。
We need to take some very large numbers and display them in an abbreviated fashion like this:
2113546998.37 --> 21.37B
15481063.31 --> 15.31M
And so on. I do not think Oracle has a method for doing this. Was hoping for some help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用日志和力量来操纵和解释价值;要将其四舍五入到十进制位置,因为它是最近的“大数字”括号:
然后要获得以下字母,类似的东西,
依此类推,尽管您要大于此,则必须决定如何区分四周和Quintillion。
样本数据,完整查询:
获取
和 M对于您的两个原始值,而不是21.37b
正如您的问题所示,15.31m - 但正如评论中指出的那样,只保留两个极端的精确度并没有意义。当然,可以做到这一点 - 地板而不是圆,并附加原始小数部分 - 但似乎这不太可能是您真正的意思,我认为21 vs 2和十进制部分是错误,将问题放在一起。
但是,您可能不想将其应用于较小的数字 - “ K”可能不太常见? - 如果是这样,您可以使用另一个案例表达式决定。例如:
逻辑放入函数中
00afdle = 00af7ae30fcfd6d35f5d7ce9514329d7” ;如果您需要处理零或负数,则需要。
You could use log and power to manipulate and interpret the value; to get it rounded to decimal places for it's nearest 'large number' bracket:
And then to get the letter to append, something like:
and so on, though if you get larger than that you'll have to decide how to distinguish between quadrillion and quintillion.
With some extended sample data, a full query of:
gets
So that gets 2.11B and 15.48M for your two original values, not 21.37B
and 15.31M as your question showed - but as pointed out in comments, it wouldn't really make sense to only keep both extremes of the precision. It's possible do do that, of course - floor instead of round, and append the original decimal part - but it seems unlikely that's what you really meant, and I've assume both 21 vs 2 and the decimal parts are mistakes putting the question together.
You might not want to apply it to smaller numbers though - 'K' is perhaps less common? - and if so you could use another case expression to decide. For example:
Either way you can easily put the logic into a function.
db<>fiddle
I've only looked at positive, non-zero numbers; if you need to handle zero or negative numbers then it will need a little bit more work.