oracle spool header 分隔符
oracle spool header seperator
从 sqlplus 假脱机到 csv 时遇到问题...
这是我的脚本:
connect dbread/dbreadonly@p01 ;
set heading on
set pagesize 50000
set underline off
set headsep "|"
set linesize 1000
set echo off
set feedback off
set space 0
set verify off
set trimspool on
set markup html off
col lifnr for a10 truncated
col bukrs for a4 truncated
col name1 for a35 truncated
col stras for a35 truncated
col ort01 for a30 truncated
col pstlz for a10 truncated
col pfach for a10 truncated
col land1 for a3 truncated
col telf1 for a16 truncated
col telfx for a16 truncated
col stceg for a20 truncated
col bankl for a15 truncated
col bankn for a18 truncated
col smtp_addr for a35 truncated
spool d:\Kofax_Rechnungseingang\Unload\Vendors.csv
select a.lifnr, ';', b.bukrs, ';', a.name1, ';', a.stras, ';', a.ort01, ';', a.pstlz, ';', a.pfach, ';', a.land1, ';', a.telf1, ';', a.telfx, ';', a.stceg, ';', c.bankl, ';', c.bankn, ';', d.smtp_addr
from sapsr3.lfa1 a, sapsr3.lfb1 b, sapsr3.lfbk c, sapsr3.adr6 d
where b.bukrs = '1000'
and a.lifnr = b.lifnr
and c.lifnr = a.lifnr
and d.addrnumber = a.adrnr
and d.persnumber = ' '
and d.home_flag = 'X'
and a.loevm = ' '
and b.loevm = ' '
order by 1
;
spool off
这是输出:
LIFNR';'BUKR';'NAME1 ';'STRAS ';'ORT01 ';'PSTLZ ';'PFACH ';' LAN' ; 'TELF1 ';' TELFX ';'STCEG ';'BANKL ';'BANKN ';'SMTP_ADDR
0000000011; 1000; xxxxxxxx ; xxxxxxxxx ; xxxxx ; xxxx ; xxxxxx ; DE ; xxxxxxx ; xxxxxxx ; xxxxxxx ; xxxxxxxxx ; xxxxxxxxx ; xxxxxxx
输出一切正常 - 但 header 分隔符 ';'应该只是分号,就像在数据输出中一样。
哪里出错了??
此致
帕特里克
您可以尝试给您的分号字段起一个别名 ";"
;例如:
SQL> select 1 as one, ';' as ";", 2 as two, ';' as ";", 3 as three from dual;
ONE ; TWO ; THREE
---------- - ---------- - ----------
1 ; 2 ; 3
另一种方法是使用 set colsep
:
SET COLSEP ";"
SELECT 'abcde' col1, 123456 col2, 'abc' col3 FROM dual UNION ALL
SELECT 'efy' col1, 9875 col2, 'howdy' col3 FROM dual;
COL1 ; COL2;COL3
-----;----------;-----
abcde; 123456;abc
efy ; 9875;howdy
从 sqlplus 假脱机到 csv 时遇到问题...
这是我的脚本:
connect dbread/dbreadonly@p01 ;
set heading on
set pagesize 50000
set underline off
set headsep "|"
set linesize 1000
set echo off
set feedback off
set space 0
set verify off
set trimspool on
set markup html off
col lifnr for a10 truncated
col bukrs for a4 truncated
col name1 for a35 truncated
col stras for a35 truncated
col ort01 for a30 truncated
col pstlz for a10 truncated
col pfach for a10 truncated
col land1 for a3 truncated
col telf1 for a16 truncated
col telfx for a16 truncated
col stceg for a20 truncated
col bankl for a15 truncated
col bankn for a18 truncated
col smtp_addr for a35 truncated
spool d:\Kofax_Rechnungseingang\Unload\Vendors.csv
select a.lifnr, ';', b.bukrs, ';', a.name1, ';', a.stras, ';', a.ort01, ';', a.pstlz, ';', a.pfach, ';', a.land1, ';', a.telf1, ';', a.telfx, ';', a.stceg, ';', c.bankl, ';', c.bankn, ';', d.smtp_addr
from sapsr3.lfa1 a, sapsr3.lfb1 b, sapsr3.lfbk c, sapsr3.adr6 d
where b.bukrs = '1000'
and a.lifnr = b.lifnr
and c.lifnr = a.lifnr
and d.addrnumber = a.adrnr
and d.persnumber = ' '
and d.home_flag = 'X'
and a.loevm = ' '
and b.loevm = ' '
order by 1
;
spool off
这是输出:
LIFNR';'BUKR';'NAME1 ';'STRAS ';'ORT01 ';'PSTLZ ';'PFACH ';' LAN' ; 'TELF1 ';' TELFX ';'STCEG ';'BANKL ';'BANKN ';'SMTP_ADDR
0000000011; 1000; xxxxxxxx ; xxxxxxxxx ; xxxxx ; xxxx ; xxxxxx ; DE ; xxxxxxx ; xxxxxxx ; xxxxxxx ; xxxxxxxxx ; xxxxxxxxx ; xxxxxxx
输出一切正常 - 但 header 分隔符 ';'应该只是分号,就像在数据输出中一样。
哪里出错了??
此致 帕特里克
您可以尝试给您的分号字段起一个别名 ";"
;例如:
SQL> select 1 as one, ';' as ";", 2 as two, ';' as ";", 3 as three from dual;
ONE ; TWO ; THREE
---------- - ---------- - ----------
1 ; 2 ; 3
另一种方法是使用 set colsep
:
SET COLSEP ";"
SELECT 'abcde' col1, 123456 col2, 'abc' col3 FROM dual UNION ALL
SELECT 'efy' col1, 9875 col2, 'howdy' col3 FROM dual;
COL1 ; COL2;COL3
-----;----------;-----
abcde; 123456;abc
efy ; 9875;howdy