sql - SQL to_char 舍入 '9999.99'
问题描述
您好,我想知道是否有人可以向我解释什么 to_char(number, '999.99') 以及当 9 变为 0 时它如何影响数字的输出。
例如,如果我有数字 123.75 或 123.44,如果它是 '999.90' '990.00' '999.99' 会发生什么
只是想了解 9 和 0 在上下文中的含义
解决方案
它在任何Oracle 数据库版本的TO_CHAR
函数文档中都有解释,在Format models部分下。
- 0:返回前导/尾随零
- 9:
- 返回具有指定位数的值,如果为正,则带有前导空格,如果为负,则返回前导减号。
- 前导零为空白,但零值除外,它为定点数的整数部分返回零。
例如:
SQL> with test (col) as
2 (select 123.70 from dual union all
3 select 10.07 from dual
4 )
5 select col,
6 to_char(col, '999.90') val_1,
7 to_char(col, '990.00') val_2,
8 to_char(col, '999.99') val_3
9 from test;
COL VAL_1 VAL_2 VAL_3
---------- ------- ------- -------
123,7 123.70 123.70 123.70
10,07 10.07 10.07 10.07
SQL>
前导零:
SQL> with test (col) as
2 (select 123.70 from dual union all
3 select 10.07 from dual
4 )
5 select col,
6 to_char(col, '0999.90') val_1,
7 to_char(col, '0990.00') val_2,
8 to_char(col, '0999.99') val_3
9 from test;
COL VAL_1 VAL_2 VAL_3
---------- -------- -------- --------
123,7 0123.70 0123.70 0123.70
10,07 0010.07 0010.07 0010.07
-- -- -- --> these are leading zeros
SQL>
推荐阅读
- html - 如何让星星背景与鼠标交互
- javascript - 使用 JavaScript+HTML 设置网站 cookie
- python - python中的异步或并发
- c# - Xamarin Forms Android 应用程序在事件处理程序期间创建类对象后崩溃
- python - 合并两个数据帧以减少内存消耗
- android - Android - onClickListener 不适用于 CardView 中的 ImageButton
- visual-studio - Visual Studio 2019 扩展无限加载
- python - 无法在 cmd 中执行 python popen.read
- android - 如果我不想实现 FirebaseMessagingService,是否有替代 onNewToken 的方法?
- c++ - 如何在 C++11 中以与 C++03 中相同的方式使用 errno