Oracle SQL 中连接字符串时中间不留空格吗?
我正在尝试在 oracle 中连接字符串。
以下是我的查询:
insert into dummy values('c'||to_char(10000,'99999'));
预期结果是:
c10000
但我得到的输出在 'c' 和值 10000 之间有一个空格:
c 10000
如何在没有空格的情况下连接?
I am trying to concatenate strings in oracle.
The following is my query:
insert into dummy values('c'||to_char(10000,'99999'));
The expected result is:
c10000
But the output I get is with a space in between 'c' and the value 10000:
c 10000
How to concat without spaces?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这不是连接运算符的问题,而是函数
to_char()
的问题。尝试一下:我在此处引用手册:
This is not an issue with the concatenation operator but with the function
to_char()
. Try instead:I quote the manual here:
有两种解决方案:
FM
') 格式前缀,可抑制to_char
数字转换中的额外空白字符前缀。我建议首选这个,因为它与 to_char 格式集成,不需要额外的函数调用;to_char
数字转换返回值的LTRIM
。下面的代码显示了两种解决方案的结果:
"CONCAT('NTA',TO_CHAR(1,'FM0000000000000'))"
: "NTA0000000000001""CONCAT('NTA',LTRIM(TO_CHAR(1,'0000000000000')))"
: "NTA0000000000001""CONCAT('NTA',TO_CHAR(1,'0000000000000'))"
: "NTA 0000000000001"There are two solutions:
FM
') formatting prefix that suppresses the additional blank character prefix for theto_char
number conversion. I suggest this one is preferred, because it is integrated with the to_char format and does not require an additional function call;LTRIM
of the returned value from theto_char
number conversion.The code below shows the results of both solutions:
"CONCAT('NTA',TO_CHAR(1,'FM0000000000000'))"
: "NTA0000000000001""CONCAT('NTA',LTRIM(TO_CHAR(1,'0000000000000')))"
: "NTA0000000000001""CONCAT('NTA',TO_CHAR(1,'0000000000000'))"
: "NTA 0000000000001"