How to output oracle sql result into a file in windows?

后端 未结 5 672
旧时难觅i
旧时难觅i 2020-12-13 13:32

I tried

select * from users 
save D:\\test.sql create;

But SQL plus gives me \"no proper ended\" How to specify path in oracle sql in windo

相关标签:
5条回答
  • 2020-12-13 14:04

    Very similar to Marc, only difference I would make would be to spool to a parameter like so:

    WHENEVER SQLERROR EXIT 1
    SET LINES 32000
    SET TERMOUT OFF ECHO OFF NEWP 0 SPA 0 PAGES 0 FEED OFF HEAD OFF TRIMS ON TAB OFF
    SET SERVEROUTPUT ON
    
    spool &1
    
    -- Code
    
    spool off
    exit
    

    And then to call the SQLPLUS as

    sqlplus -s username/password@sid @tmp.sql /tmp/output.txt
    
    0 讨论(0)
  • 2020-12-13 14:09

    Having the same chore on windows 10, and windows server 2012. I found the following solution:

    echo quit |sqlplus schemaName/schemaPassword@sid @plsqlScript.sql > outputFile.log
    

    Explanation

    echo quit | send the quit command to exit sqlplus after the script completes

    sqlplus schemaName/schemaPassword@sid @plsqlScript.sql execute plssql script plsqlScript.sql in schema schemaName with password schemaPassword connecting to SID sid

    > outputFile.log redirect sqlplus output to log file outputFile.log

    0 讨论(0)
  • 2020-12-13 14:19
    spool "D:\test\test.txt"
    
    select  
      a.ename  
    from  
      employee a  
    inner join department b  
    on  
    (  
      a.dept_id = b.dept_id  
    )  
    ;  
    spool off  
    

    This query will spool the sql result in D:\test\test.txt

    0 讨论(0)
  • 2020-12-13 14:21

    just to make the Answer 2 much easier, you can also define the folder where you can put your saved file

        spool /home/admin/myoutputfile.txt
        select * from table_name;
        spool off;
    

    after that only with nano or vi myoutputfile.txt, you will see all the sql track.

    hope is that help :)

    0 讨论(0)
  • 2020-12-13 14:26

    Use the spool:

    spool myoutputfile.txt
    select * from users;
    spool off;
    

    Note that this will create myoutputfile.txt in the directory from which you ran SQL*Plus.

    If you need to run this from a SQL file (e.g., "tmp.sql") when SQLPlus starts up and output to a file named "output.txt":

    tmp.sql:

    select * from users;
    

    Command:

    sqlplus -s username/password@sid @tmp.sql > output.txt
    

    Mind you, I don't have an Oracle instance in front of me right now, so you might need to do some of your own work to debug what I've written from memory.

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