Spool Command: Do not output SQL statement to file

后端 未结 5 739
闹比i
闹比i 2020-11-28 12:22

I am wanting to output a Query to a CSV file and am using the below as a small test;

spool c:\\test.csv 
select /*csv*/ username, user_id, created from all_u         


        
相关标签:
5条回答
  • 2020-11-28 12:40

    Exec the query in TOAD or SQL DEVELOPER

    ---select /*csv*/ username, user_id, created from all_users;
    

    Save in .SQL format in "C" drive

    --- x.sql
    

    execute command

    ---- set serveroutput on
         spool y.csv
         @c:\x.sql
         spool off;
    
    0 讨论(0)
  • 2020-11-28 12:41

    My shell script calls the sql file and executes it. The spool output had the SQL query at the beginning followed by the query result.

    This did not resolve my problem:

    set echo off
    

    This resolved my problem:

    set verify off
    
    0 讨论(0)
  • 2020-11-28 12:53

    Unfortunately SQL Developer doesn't fully honour the set echo off command that would (appear to) solve this in SQL*Plus.

    The only workaround I've found for this is to save what you're doing as a script, e.g. test.sql with:

    set echo off
    spool c:\test.csv 
    select /*csv*/ username, user_id, created from all_users;
    spool off;
    

    And then from SQL Developer, only have a call to that script:

    @test.sql
    

    And run that as a script (F5).

    Saving as a script file shouldn't be much of a hardship anyway for anything other than an ad hoc query; and running that with @ instead of opening the script and running it directly is only a bit of a pain.


    A bit of searching found the same solution on the SQL Developer forum, and the development team suggest it's intentional behaviour to mimic what SQL*Plus does; you need to run a script with @ there too in order to hide the query text.

    0 讨论(0)
  • 2020-11-28 12:55

    You can directly export the query result with export option in the result grig. This export has various options to export. I think this will work.

    0 讨论(0)
  • 2020-11-28 13:00
    set echo off
    spool c:\test.csv 
    select /*csv*/ username, user_id, created from all_users;
    spool off;
    
    0 讨论(0)
提交回复
热议问题