2

I have the below in a bash script. The inputsqls.txt file contains 10 SQL statements that take several hours to run. Is there a way to periodically write the results to output.txt before all 10 statements have run? i.e. every 30mins write the results of all queries executed to the file or each time one query completes update the file, so that you can check say 4 of the query results without having to wait for all 10 to complete.

Eventually output.txt should contain the results of all 10 queries.

sqlplus -l <<sqlly > output.txt
    USER/PASSWORD@SID
    @inputsqls.txt
    EXIT
sqlly

Note: breaking up each file to have just one statement is not an ideal workaround.

4

2 回答 2

3

使用 inputsqls.txt 中的 SQL*Plus假脱机命令

spool output.txt append

这会将打印到 stdout 的任何内容附加到 output.txt 写入时。

如果启动时 output.txt 不存在,只需删除append

spool output.txt
于 2012-05-05T09:34:46.353 回答
0

这取决于 SQL 语句在完成之前是否生成任何输出。如果它们都运行了很长时间然后对结果进行排序,那么输出可能只会在过程的最后。

您拥有它的方式可能是最好的方式,因为output.txt无论如何都会定期刷新,从而导致文件的定期更新。但是,如果所有输出都在末尾,则不会发生这种情况。

一种可能性是单独分解十个查询(假设您按顺序而不是并行运行它们。这可能允许每个查询更快地完成并输出其结果,例如:

sqlplus -l <<sqlly > output.txt
    USER/PASSWORD@SID
    @inputsqls_01.txt
    EXIT
sqlly
sqlplus -l <<sqlly >> output.txt
    USER/PASSWORD@SID
    @inputsqls_02.txt
    EXIT
sqlly
:
sqlplus -l <<sqlly >> output.txt
    USER/PASSWORD@SID
    @inputsqls_10.txt
    EXIT
sqlly
于 2012-05-05T09:31:57.653 回答