如何从SQLPLUS中删除空格?

时间:2013-07-06 20:46:26

标签: shell sqlplus

我有一个文件:

set linesize 1000
set trimspool on
set trimout on
set pagesize 0
set feedback off

spool result.csv

SELECT process_id || ';' || file_name || ';' || source || ';' || destination || ';' || type || ';' || transfer_name || ';' || message || ';' || message2  || ';' || destination_sub_group
FROM table
WHERE process_id = '12345';

而且SQLPLUS正在调用它 但这是返回空格,特别是message2字段,有关如何删除它的任何想法吗?

这是输出:

12345;filename.txt;X;X;4;X;xx =  xxxx

Warning: Using insecure memory!

Decoding data....
Secret key is required to read it.
Key for user ID "X"
Error decrypting file '/apps/egs/gen/file_name.txt.pgp'.
;INBOUND

谢谢!

  • 我用X替换了一些值。

这是我想要的输出:

12345;filename.txt;X;X;4;X;xx = xxxx Warning: Using insecure memory! Decoding data.... Secret key is required to read it. Key for user ID "X" Error decrypting file /apps/egs/gen/file_name.txt.pgp'.;INBOUND

3 个答案:

答案 0 :(得分:1)

当我想将查询结果放入 csv 时,我已经解决了这个问题好几天了... set mark csv ON 在那种情况下最终解决了这个问题……我花了很长时间才找到那个命令

答案 1 :(得分:0)

尝试使用TRIM删除尾随空格和REPLACE以删除换行符和回车符:

    SELECT process_id || ';' || file_name || ';' || source || ';' || destination || ';' || type || ';' || transfer_name || ';' || message || ';' || 
    replace(replace(trim(message2),CHR(10),' '),CHR(13),' ')  || ';' || destination_sub_group
    FROM table WHERE process_id = '12345';

答案 2 :(得分:0)

添加以下内容:

COL the_stuff形式a1000

然后在查询中添加“the_stuff”列别名:

SELECT process_id .... destination_sub_group the_stuff from ..

这将明确允许您控制此输出的显示方式。

接下来,要处理输出中的嵌入式换行符,请在TRANSLATE(...,CHR(10),'+')周围进行换行。

E.g。

这显示了包含换行符的数据:

SQL> select 'line 1' || chr(10) || 'line2' || chr(10) || 'line 3' txt from dual;

TXT
-------------------
line 1
line2
line 3

翻译以用“+”替换换行符:

SQL> select translate ( 'line 1' || chr(10) || 'line2' || chr(10) || 'line 3',
                        chr(10), '+' ) txt  
    from dual;

TXT
-------------------
line 1+line2+line 3

SQL>
相关问题