oracle11g - 在 SQL Plus 中,当在 Oracle 11g 及更高版本中使用 lpad 时,第二列会获得额外的尾随空格
问题描述
示例代码:
spool "xy2.dat"
set heading off
set pause off
set termout off
set linesize 164
select 'start', lpad(current_date,12,'0'), current_date, 'gap', current_date, 'end' from dual
/
spool off
Oracle 10g 输出:
start 00021-DEC-20 21-DEC-20 gap 21-DEC-20 end
Oracle 11g 及以上输出:
start 00021-DEC-20 21-DEC-20 gap 21-DEC-20 end
在上面的 Oracle 11g 的 SQL Plus 中似乎有奇怪的输出,我们是否有任何根本原因导致这种不同的行为。
解决方案
看起来即使不显示列名(HEADING OFF),它们仍然占用空间。
由于您不需要列名,一个简单的解决方案可能是使用短列别名:
SET HEADING OFF
SELECT
'start' AS c1,
LPAD( CURRENT_DATE, 12, '0' ) AS c2,
CURRENT_DATE AS c3,
'gap' AS c4,
CURRENT_DATE AS c5,
'end' AS c6
FROM dual
结果:
start 00021-DEC-20 21-DEZ-20 gap 21-DEZ-20 end
这是之前的样子:
start 00021-DEC-20 21-DEZ-20 gap 21-DEZ-20 end
推荐阅读
- android - 如何重新生成 Build Gradle:模块应用程序文件
- r - R Simmer - “键和值的数量不匹配”
- git - 对方的邮件只收到明文,没有补丁文件,我用 $ git send-email *.patch 发邮件
- regex - 用于失败子域的正则表达式
- c++11 - OpenCL2.0 运行时编译器不支持 c++11
- post - 为什么红色语言的POST会自动将参数的第一个字符变为大写?
- amazon-web-services - 如何在亚马逊 ec2 服务器上部署 codeigniter 应用程序?
- jpql - jpql 语句语法错误,不是有效的条件表达式
- google-apps-script - if 条件下相同的值不匹配
- algorithm - 为什么 Floyd Warshall 算法只需要 O(n^2) 空间?