3 回答

TA貢獻(xiàn)1789條經(jīng)驗(yàn) 獲得超10個(gè)贊
您也可以使用以下內(nèi)容,盡管它確實(shí)在字段之間引入了空格。
set colsep , -- separate columns with a comma
set pagesize 0 -- No header rows
set trimspool on -- remove trailing blanks
set headsep off -- this may or may not be useful...depends on your headings.
set linesize X -- X should be the sum of the column widths
set numw X -- X should be the length you want for numbers (avoid scientific notation on IDs)
spool myfile.csv
select table_name, tablespace_name
from all_tables
where owner = 'SYS'
and tablespace_name is not null;
產(chǎn)出如下:
TABLE_PRIVILEGE_MAP ,SYSTEM
SYSTEM_PRIVILEGE_MAP ,SYSTEM
STMT_AUDIT_OPTION_MAP ,SYSTEM
DUAL ,SYSTEM
...
這將比鍵入所有字段并將它們與逗號(hào)連接起來要簡(jiǎn)單得多。如果需要,可以使用一個(gè)簡(jiǎn)單的sed腳本來刪除逗號(hào)前面的空格。
像這樣的東西可能有用.(我的sed技能很生疏,所以這可能需要工作)
sed 's/\s+,/,/' myfile.csv

TA貢獻(xiàn)1833條經(jīng)驗(yàn) 獲得超4個(gè)贊
我將此命令用于提取維度表(DW)數(shù)據(jù)的腳本。因此,我使用以下語法:
set colsep '|'
set echo off
set feedback off
set linesize 1000
set pagesize 0
set sqlprompt ''
set trimspool on
set headsep off
spool output.dat
select '|', <table>.*, '|'
from <table>
where <conditions>
spool off
而且起作用了。我不使用sed格式化輸出文件。
添加回答
舉報(bào)