oracle 尝试从 SQL Developer 导出时,SPOOL 返回空文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26007399/
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-19 02:31:48  来源:igfitidea点击:

SPOOL returns empty files when trying to export from SQL Developer

oracleoracle11goracle-sqldeveloper

提问by JamesF

I have a series of queries that I want to output to .csv files. The only tool I have to query the database is SQL Developer.

我有一系列要输出到 .csv 文件的查询。我必须查询数据库的唯一工具是 SQL Developer。

I could run each query and then use the Export dialogue in SQL Developer to write them to files, but that's cumbersome, particularly when this needs to be done for multiple files every day.

我可以运行每个查询,然后使用 SQL Developer 中的导出对话框将它们写入文件,但这很麻烦,尤其是当每天需要为多个文件执行此操作时。

This works for some people Directly export a query to CSV using SQL Developer

这适用于某些人 使用 SQL Developer 直接将查询导出到 CSV

But it doesn't work for me.

但这对我不起作用。

For example, if I try

例如,如果我尝试

spool "C:\Users\james.foreman\Downloads\Temp\myfile.csv"

select distinct placement_type
FROM jf_placements;

spool off;

then in the script output pane of SQL Developer, I see

然后在 SQL Developer 的脚本输出窗格中,我看到

Cannot create SPOOL file C:\Users\james.foreman\Downloads\Temp\myfile.csv

无法创建 SPOOL 文件 C:\Users\james.foreman\Downloads\Temp\myfile.csv

and although myfile.csv is created, there's no results. (There are two rows returned by the query.)

虽然创建了 myfile.csv,但没有结果。(查询返回了两行。)

My first thought was that there was a permissions issue writing to C:\Users\james.foreman\Downloads\Temp but that doesn't appear to be the case, because if I delete the myfile.csv and then run the SQL, the myfile.csv file is recreated, but it never has anything in it.

我的第一个想法是写入 C:\Users\james.foreman\Downloads\Temp 时存在权限问题,但事实并非如此,因为如果我删除 myfile.csv 然后运行 ​​SQL,重新创建 myfile.csv 文件,但其中没有任何内容。

So I assume this is a configuration issue, either with the Windows machine I'm running SQL Developer on, or with my SQL Developer set up. Where should I look to investigate further?

所以我认为这是一个配置问题,无论是在我运行 SQL Developer 的 Windows 机器上,还是在我的 SQL Developer 设置中。我应该去哪里进一步调查?

@Devolus 's answer to Procedure to export table to multiple csv filesincludes the instruction "In the SQL Window right click -> Change Window to -> Command Window" but if I right click on the SQL Window, I don't see a Change Window option.

@Devolus对将表导出到多个 csv 文件的过程的回答包括指令“在 SQL 窗口中右键单击 -> 将窗口更改为 -> 命令窗口”但如果我右键单击 SQL 窗口,我看不到更改窗口选项。

(Running Windows 7, SQL Developer Version 4.0.2.15, Build 15.21, database is Oracle 11.2)

(运行Windows 7,SQL Developer Version 4.0.2.15,Build 15.21,数据库为Oracle 11.2)

采纳答案by Lalit Kumar B

The fact that the file is created, but has no data, perhaps, the last statement, SPOOL OFFis not yet executed. Add a new line in the script and try again.

文件已创建,但没有数据的事实,也许是最后一条语句,SPOOL OFF尚未执行。在脚本中添加一个新行并重试。

For example, your script would look like :

例如,您的脚本如下所示:

    spool "C:\Users\james.foreman\Downloads\Temp\myfile.csv"

    select distinct placement_type
    FROM jf_placements
    /

    spool off
    /

-- need a new line to make sure spool off executes

回答by Keny

When you run your script, press "Run Script" instead of "Run Statment" or you may press F5.

当您运行脚本时,请按“运行脚本”而不是“运行语句”,或者您可以按 F5。

It fixed my problem, hope it can fix yours too

它解决了我的问题,希望它也能解决你的问题

回答by user2501375

In my case, it took two things to fix the problem:

就我而言,解决问题需要两件事:

  • running from a script (using @C:\file.sql notation)
  • upgrading to the latest version of SQL Developer
  • 从脚本运行(使用 @C:\file.sql 符号)
  • 升级到最新版本的 SQL Developer

I was running SQL Developer 3.2.20.09 (doesn't work), and now use 4.0.2.51 (exact same script works).

我正在运行 SQL Developer 3.2.20.09(不起作用),现在使用 4.0.2.51(完全相同的脚本工作)。

Also,

还,

回答by Osama Al-Banna

My problem solved after I highlight the whole script and press F5 in SQL developer .

在我突出显示整个脚本并在 SQL developer 中按 F5 后,我的问题解决了。