oracle sql-如何将sql查询中的数据输出为excel格式

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5812701/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 23:31:01  来源:igfitidea点击:

sql-how to output data from sql query to excel format

sqloracle

提问by fuad

I'd like to get the results from a SQL query in Excel format.

我想从 Excel 格式的 SQL 查询中获取结果。

For example:

例如:

SQL> clear breaks
breaks cleared
SQL> clear columns
columns cleared
SQL> clear compute
computes cleared
SQL> set pagesize 1000
SQL> set NEWPAGE 1
SQL> set linesize 100
SQL> column id format a15
SQL> column tarikh format a14
SQL> column jenis_pengguna format a15
SQL> Ttitle center 'ANALISIS PENGGUNAAN PORTAL BULAN APRIL 2011' skip 1 - center----------------------------------------------------------------------------skip3
SQL> set linesize 100
SQL> break on id skip 2 on tarikh
SQL> compute count of tarikh on id
SQL> SELECT id, tarikh, jenis_pengguna 
       FROM PENGGUNAAN 
      WHERE tarikh >= (sysdate)-30 
   GROUP BY (id, tarikh, jenis_pengguna);

Now, how would I get results that Excel could use or import?

现在,我将如何获得 Excel 可以使用或导入的结果?

回答by DCookie

One Excel format you can produce is comma separated value, or CSV. Simply do this with your select:

您可以生成的一种 Excel 格式是逗号分隔值或 CSV。只需使用您的选择执行此操作:

set feedback off
set linesize 100
set pagesize 0
spool yourfile.csv

SELECT id||','||tarikh||','||jenis_pengguna
  FROM penggunaan
 WHERE tarikh >= (sysdate)-30 
 GROUP BY (id, tarikh, jenis_pengguna);

You may have to tweak a few other settings to get a clean data-only output, but this should get you going. You can then read the file with Excel.

您可能需要调整一些其他设置以获得干净的纯数据输出,但这应该可以帮助您。然后,您可以使用 Excel 读取该文件。