sql - 为什么 0 是 to_char(0,'B9999') 的例外?
问题描述
是什么让数字 0 成为 Oracle to_char(number,'B9999') 掩码的例外?在这个查询中,0 根本不打印。
我怎样才能用空格填充我的所有数字,包括 0?是lpad()
唯一的选择吗?
select to_char(0,'B09999') as num_fmt from dual union all
select to_char(0,'B9999') as num_fmt from dual union all
select to_char(300,'B9999') as num_fmt from dual union all
select to_char(-300,'B9999') as num_fmt from dual ;
解决方案
您可以使用to_char(yourVal,'999')
格式模型为三位整数获取左侧填充空白(前导零为空白,零值除外)。
如果您需要更多,而不是将整数值中的九位数增加到位数:
select to_char(0,'999') as num_fmt from dual union all
select to_char('00','999') from dual union all
select to_char('016','999') from dual union all
select to_char(17,'999') from dual union all
select to_char(314,'999') from dual union all
select to_char(-314,'999') from dual;
NUM_FMT
-------
0
0
16
17
314
-314
推荐阅读
- reactjs - Jest、Enzyme、React、Next.js、Typescript .default 不是构造函数
- typescript - 我们如何在 describe 中使用 async/await?
- kubernetes - 纠正 GKE 集群中的时钟偏差
- c++ - const_cast 是如何工作的?
- javascript - 有没有办法将 js 文件动态加载为 es6 模块?(如 $.getScript)
- facebook-graph-api - 有没有办法判断它是 Instagram 创建者还是企业帐户?
- docker - Kafka Connect S3 - partitioner.class - 找不到 TimeBasedPartitioner
- sql - 降低表值函数的成本 - 查询计划中的 XML 阅读器 - 如何?
- swift - 如何将屏幕亮度设置为特定值?IODisplaySetFloatParameter 没有按预期改变屏幕亮度
- python - 在python中通过控制台输入数据