为什么 TO

编程入门 行业动态 更新时间:2024-10-24 01:54:52
本文介绍了为什么 TO_CHAR 在数字开头添加空格(一个白色字符)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

当我根据此代码准备此 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

本文发布于:2023-10-25 14:12:32,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1527190.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!