Marvin Wong
Marvin Wong

Reputation: 519

SQL Plus SP2-0606

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

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.

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:

    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??..

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

Upvotes: 4

Views: 31300

Answers (5)

ALOK
ALOK

Reputation: 21

this error is just because of , not having "WRITE" privileges on directory where you are creating the spool file.

Solution
give or ask to give the permission to you who is owner of that directory, if its not owned by you using chmod. for ex- full permission to all chmod 777 <file/directory name>

Upvotes: 2

sandeepEswar
sandeepEswar

Reputation: 1

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'

Upvotes: -1

JessePinkman
JessePinkman

Reputation: 651

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.

Upvotes: 2

Frank Schmitt
Frank Schmitt

Reputation: 30845

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 ';':

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).

UPDATE

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

spool on

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

Upvotes: 5

Lalit Kumar B
Lalit Kumar B

Reputation: 49112

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.

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

For example,

Client: 12c

OS : 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.

Upvotes: 1

Related Questions