我是 Oracle 新手,发现有些东西很难理解。尽管我了解 TO_CHAR 的功能,但我对数字格式模型的概念很陌生。请帮我理解下面的逻辑。
select TRIM(substr(TO_CHAR (160, '000'),1,3)) from dual;
Output -> 16
select TRIM(substr(TO_CHAR (160),1,3)) from dual;
Output -> 160
For the 1st query why has the oracle returned the value 16 rather than 160?
最佳答案
以 FM
开头的格式字符串,例如“FM000”
。
如果没有 FM
,前面会保留一个空格作为减号。
select '|' || to_char(160,'000') || '|' as no_FM
,'|' || to_char(160,'FM000') || '|' as with_FM
from dual
+--------+---------+
| NO_FM | WITH_FM |
+--------+---------+
| | 160| | |160| |
+--------+---------+
关于sql - TO_CHAR函数逻辑<<数字格式>>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42241873/