如何在 Oracle SQL Developer 中将查询结果导出到 csv?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4168398/
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
How to export query result to csv in Oracle SQL Developer?
提问by Ken Liu
I'm using Oracle SQL Developer 3.0. Trying to figure out how to export a query result to a text file (preferably CSV). Right clicking on the query results window doesn't give me any export options.
我正在使用 Oracle SQL Developer 3.0。试图弄清楚如何将查询结果导出到文本文件(最好是 CSV)。右键单击查询结果窗口不会给我任何导出选项。
回答by Ian Carpenter
Version I am using
我正在使用的版本
Update 5th May 2012
2012 年 5 月 5 日更新
Jeff Smithhas bloggedshowing, what I believe is the superior method to get CSV output from SQL Developer. Jeff's method is shown as Method 1 below:
Jeff Smith在博客中展示了我认为从 SQL Developer 获取 CSV 输出的最佳方法。Jeff 的方法如下面的方法 1 所示:
Method 1
方法一
Add the comment /*csv*/
to your SQL query and run the query as a script (using F5 or the 2nd execution button on the worksheet toolbar)
将注释添加/*csv*/
到您的 SQL 查询并将查询作为脚本运行(使用 F5 或工作表工具栏上的第二个执行按钮)
That's it.
就是这样。
Method 2
方法二
Run a query
运行查询
Right click and select unload.
右键单击并选择卸载。
Update. In Sql Developer Version 3.0.04 unload has been changed to exportThanks to Janis Peisenieks for pointing this out
更新。在 Sql Developer 版本 3.0.04 中卸载已更改为导出感谢 Janis Peisenieks 指出这一点
Revised screen shot for SQL Developer Version 3.0.04
SQL Developer 版本 3.0.04 的修订屏幕截图
From the format drop down select CSV
从格式下拉列表中选择 CSV
And follow the rest of the on screen instructions.
并按照屏幕上的其余说明进行操作。
回答by BQ.
Not exactly "exporting," but you can select the rows (or Ctrl-Ato select all of them) in the grid you'd like to export, and then copy with Ctrl-C.
不完全是“导出”,但您可以选择要导出的网格中的行(或Ctrl-A以选择所有行),然后使用Ctrl-进行复制C。
The default is tab-delimited. You can paste that into Excel or some other editor and manipulate the delimiters all you like.
默认为制表符分隔。您可以将其粘贴到 Excel 或其他一些编辑器中,并随心所欲地操作分隔符。
Also, if you use Ctrl-Shift-Cinstead of Ctrl-C, you'll also copy the column headers.
此外,如果您使用Ctrl- Shift-C而不是Ctrl- C,您还将复制列标题。
回答by Yves Rochon
FYI, you can substitute the /*csv*/
for other formats as well including /*xml*/
and /*html*/
.
select /*xml*/ * from emp
would return an xml document with the query results for example.
I came across this article while looking for an easy way to return xml from a query.
仅供参考,您也可以替换/*csv*/
其他格式,包括/*xml*/
和/*html*/
。例如,select/*xml*/ * from emp
将返回一个带有查询结果的 xml 文档。我在寻找一种从查询中返回 xml 的简单方法时遇到了这篇文章。
回答by BoeroBoy
FYI to anyone who runs into problems, there is a bug in CSV timestamp export that I just spent a few hours working around. Some fields I needed to export were of type timestamp. It appears the CSV export option even in the current version (3.0.04 as of this posting) fails to put the grouping symbols around timestamps. Very frustrating since spaces in the timestamps broke my import. The best workaround I found was to write my query with a TO_CHAR() on all my timestamps, which yields the correct output, albeit with a little more work. I hope this saves someone some time or gets Oracle on the ball with their next release.
仅供遇到问题的任何人使用,CSV 时间戳导出中有一个错误,我只是花了几个小时来解决这个问题。我需要导出的一些字段是时间戳类型。即使在当前版本(截至本文发布时为 3.0.04)中,CSV 导出选项似乎也无法将分组符号放在时间戳周围。非常令人沮丧,因为时间戳中的空格破坏了我的导入。我找到的最好的解决方法是在我的所有时间戳上使用 TO_CHAR() 编写我的查询,这会产生正确的输出,尽管需要做更多的工作。我希望这可以为某人节省一些时间,或者让 Oracle 在他们的下一个版本中有所作为。
回答by John
CSV Export does not escape your data. Watch out for strings which end in \
because the resulting \"
will look like an escaped "
and not a \
. Then you have the wrong number of "
and your entire row is broken.
CSV 导出不会转义您的数据。注意以 结尾的字符串,\
因为结果\"
看起来像是转义的"
而不是\
. 然后你有错误的数字,"
你的整行都坏了。
回答by Arpan Saini
To take an export to your local system from sql developer.
从 sql developer 导出到本地系统。
Path : C:\Source_Table_Extract\des_loan_due_dtls_src_boaf.csv
SPOOL "Path where you want to save the file"
SELECT /*csv*/ * FROM TABLE_NAME;