Directly export a query to CSV using SQL Developer

后端 未结 3 1680
攒了一身酷
攒了一身酷 2020-12-09 03:14

Using SQL Developer to run queries works good, but I would save a lot of time if I instead of first running the query and then right click the result set and go through the

相关标签:
3条回答
  • 2020-12-09 03:50

    After Ctrl+End, you can do the Ctrl+A to select all in the buffer and then paste into Excel. Excel even put each Oracle column into its own column instead of squishing the whole row into one column. Nice..

    0 讨论(0)
  • 2020-12-09 03:52

    You can use the spool command (SQL*Plus documentation, but one of many such commands SQL Developer also supports) to write results straight to disk. Each spool can change the file that's being written to, so you can have several queries writing to different files just by putting spool commands between them:

    spool "\path\to\spool1.txt"
    
    select /*csv*/ * from employees;
    
    spool "\path\to\spool2.txt"
    
    select /*csv*/ * from locations;
    
    spool off;
    

    You'd need to run this as a script (F5, or the second button on the command bar above the SQL Worksheet). You might also want to explore some of the formatting options and the set command, though some of those do not translate to SQL Developer.

    Since you mentioned CSV in the title I've included a SQL Developer-specific hint that does that formatting for you.

    A downside though is that SQL Developer includes the query in the spool file, which you can avoid by having the commands and queries in a script file that you then run as a script.

    0 讨论(0)
  • 2020-12-09 04:07

    Click in the grid so it has focus.

    Ctrl+End

    This will force the rest of the records back into the grid.

    All credit to http://www.thatjeffsmith.com/archive/2012/03/how-to-export-sql-developer-query-results-without-re-running-the-query/

    0 讨论(0)
提交回复
热议问题