SQL Plus SP2-0606

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

SQL Plus SP2-0606

sqloraclesqlplus

提问by Marvin Wong

Using SQL tool, I want to create a text file that has a VARCHAR records.

使用 SQL 工具,我想创建一个具有 VARCHAR 记录的文本文件。

Using SQL Developer I have successfully created the output text file by calling a script. But based on my research, the TRIMSPOOl command is currently not supported by SQL Developer, making my output to have trailing spaces.

使用 SQL Developer,我通过调用脚本成功创建了输出文本文件。但根据我的研究,SQL Developer 目前不支持 TRIMSPOOl 命令,这使得我的输出有尾随空格。

Here is the code in the script:

这是脚本中的代码:

    spool on
    set echo off
    set verify off
    set feedback off
    set heading off
    set trimspool on
    set termout off
    spool C:\SQLFiles\Output.txt;
    select cust_name || cust_addr as Cust_Details
    from customer_db;
    spool off;
    

I now have the SQL Plus 11g, and I'm trying to run the script i created in SQL Developer. I'm getting an SP2-0606 error, saying:

我现在有 SQL Plus 11g,我正在尝试运行我在 SQL Developer 中创建的脚本。我收到一个 SP2-0606 错误,说:

    SP2-0606: Cannot create SPOOL file "on.LST:
    

Based on the research I did, it is because of the Spool command, and I don't have the right to access the default folder??..

根据我所做的研究,是因为 Spool 命令,而我无权访问默认文件夹??..

Can you help please on what setup I should change do to make the desired result in SQL Plus.

你能帮忙看看我应该改变什么设置来在 SQL Plus 中产生所需的结果。

回答by Frank Schmitt

You have to put the file name in double quotes - I guess SQLPlus uses C-style escape sequences, giving the backslash \a special meaning. Also, you should remove the semicolon ';':

您必须将文件名放在双引号中 - 我猜 SQLPlus 使用 C 风格的转义序列,给反斜杠\一个特殊的含义。此外,您应该删除分号“;”:

So if you replace

所以如果你更换

spool C:\SQLFiles\Output.txt;

with

spool "C:\SQLFiles\Output.txt"

it should work as expected (if C:\SQLFiles exists and is writable for your account).

它应该按预期工作(如果 C:\SQLFiles 存在并且可以为您的帐户写入)。

UPDATE

更新

As @LalitKumarB has pointed out, spool works perfectly fine without the double quotes. The real problem is elsewhere:

正如@LalitKumarB 所指出的那样,没有双引号的 spool 工作得很好。真正的问题在别处:

spool on

This tells SQLPlus to create an output file onin the current directory. So you'll get this error message if you don't have access to the directory you're starting SQLPlus from.

这告诉 SQLPluson在当前目录中创建一个输出文件。因此,如果您无权访问启动 SQLPlus 的目录,您将收到此错误消息。

回答by no_one

You are getting this error because of permission issues. Either open your command prompt window in administrator mode or save your file to a location where admin permission is not required.

由于权限问题,您收到此错误。在管理员模式下打开命令提示符窗口或将文件保存到不需要管理员权限的位置。

回答by Lalit Kumar B

From the docs,

从文档中,

SP2-0606 Cannot create file file_name

Cause: The STORE command was unable to create the specified file. There may be insufficient disk space, too many open files, or read-only protection on the output directory.

Action: Check that there is sufficient disk space and that the protection on the directory allows file creation.

SP2-0606 无法创建文件 file_name

[原因] STORE 命令无法创建指定的文件。可能是磁盘空间不足,打开的文件太多,或者输出目录有只读保护。

操作:检查是否有足够的磁盘空间以及目录上的保护是否允许创建文件。

My test case shows there is nothing wrong with the spool command. I don't think there is any need of quotes at all.

我的测试用例显示 spool 命令没有任何问题。我认为根本不需要引用。

For example,

例如,

Client: 12c

客户:12c

OS : Windows 7

操作系统:Windows 7

SQL> spool D:\text.txt
SQL> select ename||to_char(empno) from emp;

ENAME||TO_CHAR(EMPNO)
--------------------------------------------------
SMITH7369
ALLEN7499
WARD7521
JONES7566
MARTIN7654
BLAKE7698
CLARK7782
SCOTT7788
KING7839
TURNER7844
ADAMS7876

ENAME||TO_CHAR(EMPNO)
--------------------------------------------------
JAMES7900
FORD7902
MILLER7934

14 rows selected.

SQL> spool off;

And the spool file looks like:

假脱机文件如下所示:

enter image description here

在此处输入图片说明

So it works without any double-quotation marks. I guess you need to really look at the directory you are using to spool.

因此它无需任何双引号即可工作。我想您需要真正查看用于假脱机的目录。

回答by sandeepEswar

When you get this error check for spaces. For example, below you see both single quotes (') but the first one has a space after it and the second one doesn't.

当您收到此错误时,请检查空格。例如,在下面您会看到两个单引号 ('),但第一个后面有一个空格,第二个没有。

SP2-0606: Cannot create SPOOL file ' E:\SQL CLASS\New folder\sql class prt'
                         SQL> spool 'E:\SQL CLASS\New folder\sql class prt'