Oracle通過SQL Plus生成CSV、Excel檔案

feelpurple發表於2016-03-17
建立一個檔案檔案,在裡面編輯要匯出的內容
檔案的名稱是emp_sal.txt

-- suppress sql output in results
set echo off
-- eliminate row count message at end
set feedback off
-- make line long enough to hold all row data
set linesize 1000
-- suppress headings and page breaks
set pagesize 0
-- eliminate SQL*Plus prompts from output
set sql prompt ''
-- eliminate trailing blanks
set trimspool on
-- send output to file
spool C:\Users\Administrator\Desktop\emp_sal.csv
select '"員工編號","名字","姓氏","薪資"' from dual
union all
select employee_id||',"'||last_name||'","'||first_name||'",'||salary from employees;
spool off
exit

在SQL Plus裡面呼叫編輯的指令碼

C:\Users\Administrator>sqlplus scott/tiger

SQL*Plus: Release 11.2.0.1.0 Production on 星期四 3月 17 10:13:49 2016

Copyright (c) 1982, 2010, Oracle.  All rights reserved.

連線到:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> @C:\Users\Administrator\Desktop\emp_sal.txt

使用excel開啟生成的檔案


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/26506993/viewspace-2058605/,如需轉載,請註明出處,否則將追究法律責任。

相關文章