当我根据此代码准备此 SQL Fiddle 时:
As I prepared this SQL Fiddle based on this code:
WITH l_cur AS (SELECT to_char(LEVEL - 1, '0000') dd FROM dual CONNECT BY LEVEL <= 10) SELECT '''' || d1.dd || '''' o, '''' || d2.dd || '''' n FROM (SELECT dd, row_number() over(ORDER BY 1) rn FROM l_cur) d1, (SELECT dd, row_number() over(ORDER BY dbms_random.random) rn FROM l_cur) d2 WHERE d1.rn = d2.rn; O N ------- ------- ' 0000' ' 0000' ' 0001' ' 0005' ' 0002' ' 0009' ' 0003' ' 0003' ' 0004' ' 0002' ' 0005' ' 0008' ' 0006' ' 0006' ' 0007' ' 0001' ' 0008' ' 0007' ' 0009' ' 0004' 10 rows selected函数 to_char 是在开头添加一个空白字符 ' '(空格).这是 Oracle 错误吗?
To function to_char is adding one blank character ' ' (space) at beginning. Is this an Oracle bug?
推荐答案不,这不是错误,而是 记录的行为.
No, it isn't a bug, it's the documented behaviour.
负返回值自动包含前导负号和正值自动包含前导空格,除非格式模型包含 MI、S 或 PR 格式元素.
Negative return values automatically contain a leading negative sign and positive values automatically contain a leading space unless the format model contains the MI, S, or PR format element.
您可以使用格式模型修饰符 改变这种行为;在这种情况下,FM '填充模式' 修饰符(尽管文档并没有真正讨论它与数字格式模型的使用):
You can use a format model modifier to change this behaviour; in this case the FM 'fill mode' modifier (although the documentation doesn't really talk about its use with number format models):
SELECT to_char(LEVEL - 1, 'fm0000') ...SQL 小提琴.
更多推荐
为什么 TO
发布评论