Export from sql to excel

我与影子孤独终老i 提交于 2019-12-08 00:52:17

问题


I run a query using sqlplus command line interface. The query will fetch some 30 million records. I need to export the result to either csv or xls format. Can anyone let me know if this is possible? Any help is much appreciated. Thanks in advance.


回答1:


Try spool myresults.csv before your select statement, which Excel can easily open.

EDIT

Like this:

SET UNDERLINE OFF
SET COLSEP ','
--That's the separator used by excel later to parse the data to columns
SET LINES 100 PAGES 100
SET FEEDBACK off
--If you don't want column headings in CSV file
SET HEADING off 
Spool ~\myresults.csv
--Now the actual query
SELECT * FROM YOUR_TABLE;
Spool OFF

EDIT 2

You might want to batch your results if you're going to query 30M records. I've never gone that far in an excel file but the limit is 65535 rows (that would be 458 files for 30M records).

I'd go with cutting up your query into block of 60K blocks and spooling each select to a different excel file, maybe by looping on an integer and concatenating it to the end of each filename.




回答2:


SET PAGESIZE 50000
SET FEEDBACK OFF
SET MARKUP HTML ON SPOOL ON
SET NUM 24
SPOOL sample.xls
SELECT * from users;
SPOOL OFF
SET MARKUP HTML OFF SPOOL OFF

This option will help you to export directly to a excel file




回答3:


SET PAGESIZE 40000

SET FEEDBACK OFF

SET MARKUP HTML ON

SET NUM 24

SPOOL file_name.xls

---- Execute your query

SPOOL OFF

SET MARKUP HTML OFF

SPOOL OFF

Spool sqlplus to xls format



来源:https://stackoverflow.com/questions/11831254/export-from-sql-to-excel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!