how to save oracle SQL queries automatically when a query is executed?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11465337/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 00:58:10  来源:igfitidea点击:

how to save oracle SQL queries automatically when a query is executed?

oraclesave

提问by Bamadeva

I want to save SQL/PLSQL queries, which are being executed by a user.

I want to save SQL/PLSQL queries, which are being executed by a user.

I use the below, and have to use appendat the end of the statement as well as saving at the beginning. But, it's headache to execute a save statement all the time after a query is executed.

I use the below, and have to use appendat the end of the statement as well as saving at the beginning. But, it's headache to execute a save statement all the time after a query is executed.

I'd like to know if there is there any command that would automatically save the queries to the file.

I'd like to know if there is there any command that would automatically save the queries to the file.

    SQL> save C:\savesueryfolder\first.sql;
    SQL> select * from emp;
    SQL> save C:\savesueryfolder\first.sql append;

回答by Anant_00

Try for SPOOL command. SPOOL command save the output into a file. you can apply following steps-

Try for SPOOL command. SPOOL command save the output into a file. you can apply following steps-

STEP 1:

STEP 1:

Provide the location where you want to spool the output.

Provide the location where you want to spool the output.

sql> SPOOL C:\Users\Anant\Desktop\temp.text

(or temp.doc depends with which extension you want to save.I recommend to go for.doc)

(or temp.doc depends with which extension you want to save.I recommend to go for.doc)

If temp.doc/temp.txtis already available then it just override the file, so be careful always try to create a new file.

If temp.doc/temp.txtis already available then it just override the file, so be careful always try to create a new file.

STEP 2:

STEP 2:

execute queries .

execute queries .

sql> SELECT * FROM EMP;

You can execute any number of queries.

You can execute any number of queries.

STEP 3:

STEP 3:

close the spool.

close the spool.

sql>SPOOL OFF 

go to specified location and check the file.

go to specified location and check the file.