When operating on the Oracle database sqlplus command line, if you want to export the results of the SQL query to a file, you can use the SPOOL
commands in SQLPlus to export the query results to the file.
Specific steps are as follows:
1. Turn on logging: Use the SPOOL command to specify the file path and file name to be output. For example:SPOOL /存放路径/oracle.txt
2. Execute SQL query statement: You can enter any SQL query statement that needs to be executed and press the Enter key to execute it.
3. Turn off logging: After the query is completed, enter the following command to turn off logging:SPOOL OFF
example:
SQL> SPOOL /home/oracle/test/oracle.txt #先配置导出文件的存放路径
SQL> SELECT * FROM test_table; #执行sql语句
SQL> SPOOL OFF #关闭日志记录,不然每执行一个sql都会导出到上面这个文件中
After performing the above operations, the query results will be saved to the /home/oracle/test/oracle.txt file.
Note that if the path to the file to be exported does not exist, please create the directory first. In addition, if you need to export user-defined string Export, you can also use the Spool+print method to achieve similar effects.
[Personal public account]
【暴科技】、【非著名运维】 --》 公众号回复 “资料” 送运维自学资料大礼包哦!
I will also share some operation and maintenance and technological knowledge above. Please pay attention to it. Thank you all.