ITPub博客

首页 > 数据库 > Oracle > Oracle通过SQL Plus生成CSV、Excel文件

Oracle通过SQL Plus生成CSV、Excel文件

原创 Oracle 作者:feelpurple 时间:2016-03-17 10:17:33 0 删除 编辑
创建一个文件文件,在里面编辑要导出的内容
文件的名称是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博客 ” ,链接:https://blog.itpub.net/26506993/viewspace-2058605/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2014-08-01

  • 博文量
    404
  • 访问量
    1673978