如何在 Oracle SQL Developer 中将查询结果导出到 csv?

发布于 2024-10-02 03:54:41 字数 88 浏览 7 评论 0 原文

我正在使用 Oracle SQL Developer 3.0。尝试弄清楚如何将查询结果导出到文本文件(最好是 CSV)。右键单击查询结果窗口不会给我任何导出选项。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

予囚 2024-10-09 03:54:41

版本我正在使用

“

更新2012年5月5日

jeff smith

方法1

将注释/*CSV*/添加到您的SQL查询中,并将查询运行为脚本(使用F5或第二个工作表工具栏上的执行按钮)

select /*csv*/ *
from emp;

“

就是这样。

您也可以使用 spool 自动将其保存为CSV文件:

spool "/path/to/file.csv";
select /*csv*/ *
from emp;
spool off;

只需确保“以脚本运行”或按 f5

方法2

运行查询

Text”

“

更新。在SQL开发人员版本3.0.04版本中已更改为导出
感谢 janis peisenieks 为此指出了

img src =“ https://i.sstatic.net/cq4qb.jpg”

< Strong> SQL开发人员版本3.0.04

下拉选择CSV

“

并按照屏幕上的其余部分进行操作。

Version I am using

Oracle SQL Developer Version 3.0.02; Build MAIN-02.37

Update 5th May 2012

Jeff Smith has blogged showing, what I believe is the superior method to get CSV output from SQL Developer. Jeff's method is shown as Method 1 below:

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)

select /*csv*/ *
from emp;

Screenshot of SQL developer executing the SQL statement above as a script showing the output automatically formatted as valid CSV.

That's it.

You can also use spool to automatically save it as a CSV file:

spool "/path/to/file.csv";
select /*csv*/ *
from emp;
spool off;

Just be sure to "Run as Script" or press F5.

Method 2

Run a query

alt text

Right click and select unload.

Update. In Sql Developer Version 3.0.04 unload has been changed to export
Thanks to Janis Peisenieks for pointing this out

alt text

Revised screen shot for SQL Developer Version 3.0.04

enter image description here

From the format drop down select CSV

alt text

And follow the rest of the on screen instructions.

橘亓 2024-10-09 03:54:41

不完全是“导出”,但您可以在要导出的网格中选择行(或 Ctrl-A 选择所有行),然后复制使用Ctrl-C

默认为制表符分隔。您可以将其粘贴到 Excel 或其他编辑器中,并根据需要操作分隔符。

另外,如果您使用 Ctrl-Shift-C 而不是 Ctrl-C ,您还将复制列标题。

Not exactly "exporting," but you can select the rows (or Ctrl-A to select all of them) in the grid you'd like to export, and then copy with Ctrl-C.

The default is tab-delimited. You can paste that into Excel or some other editor and manipulate the delimiters all you like.

Also, if you use Ctrl-Shift-C instead of Ctrl-C, you'll also copy the column headers.

我一向站在原地 2024-10-09 03:54:41

仅供参考,您可以替换 /*csv*/
也适用于其他格式,包括 /*xml*//*html*/
例如,select /*xml*/ * from emp 将返回带有查询结果的 xml 文档。
我在寻找一种从查询返回 xml 的简单方法时看到了这篇文章。

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.

山田美奈子 2024-10-09 03:54:41

仅供遇到问题的人注意,CSV 时间戳导出中存在一个错误,我刚刚花了几个小时解决该错误。我需要导出的一些字段是时间戳类型。即使在当前版本(截至本文发布时为 3.0.04)中,CSV 导出选项似乎也无法将分组符号放在时间戳周围。非常令人沮丧,因为时间戳中的空格破坏了我的导入。我发现的最好的解决方法是在所有时间戳上使用 TO_CHAR() 编写查询,这会产生正确的输出,尽管需要更多的工作。我希望这可以节省一些时间,或者让 Oracle 能够在下一个版本中做好准备。

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.

千仐 2024-10-09 03:54:41

从 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;

To take an export to your local system from 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;
拥抱我好吗 2024-10-09 03:54:41

CSV 导出不会转义您的数据。注意以 \ 结尾的字符串,因为生成的 \" 看起来像转义的 " 而不是 \ >。那么您的 " 数量错误,并且整行都被破坏了。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文