oracle 如何在unix文件中捕获sqlplus命令行输出

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18565871/
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 01:54:00  来源:igfitidea点击:

How to capture sqlplus command line output in unix file

sqloracleunixsedawk

提问by Pooja25

I am running below : sqlplus ABC_TT/asfddd@\"SADSS.it.uk.hibm.sdkm:1521/UGJG.UK.HIBM.SDKM\"afte that I am executing one stored procedure exec HOLD.TRWERI want to capture return code of the above stored procedure in unix file as I am running the above commands in unix. Please suggest.

我在下面运行:sqlplus ABC_TT/asfddd@\"SADSS.it.uk.hibm.sdkm:1521/UGJG.UK.HIBM.SDKM\"在我执行一个存储过程之后,exec HOLD.TRWER我想在 unix 文件中捕获上述存储过程的返回代码,因为我在 unix 中运行上述命令。请建议。

回答by Vijay

I guess you are looking for spool

我猜你正在寻找 spool

SQL> spool output.txt
SQL> select 1 from dual;

1
----------
1

SQL> spool off 

Now after you exit. the query/stroed procedure output will be stored in a file called output.txt

现在退出后。查询/stroed 过程输出将存储在名为 output.txt 的文件中

回答by Ed Morton

If by return codeyou mean outputthen:

如果return code你的意思是output

command > file

If by return codeyou mean exit statusthen:

如果return code你的意思是exit status

command
echo "$?" > file

If you mean something else, let us know.

如果您有其他意思,请告诉我们。

回答by user1502952

You can store command return value in variable

您可以将命令返回值存储在变量中

value=`command`

And then checking it's value

然后检查它的价值

echo "$value"

For your case to execute oracle commands within shell script,

对于在 shell 脚本中执行 oracle 命令的情况,

value=`sqlplus ABC_TT/asfddd@\"SADSS.it.uk.hibm.sdkm:1521/UGJG.UK.HIBM.SDKM\" \
       exec HOLD.TRWER`

I'm not sure about the sql query, but you can get the returned results by using

我不确定 sql 查询,但您可以通过使用获得返回的结果

value=`oraclecommand`.

To print the returned results of oracle command,

要打印 oracle 命令的返回结果,

 echo "$value"

To check whether oracle command or any other command executed successfully, just
check with $? value after executing command. Return value is 0 for success and non-zero for failure.

要检查 oracle 命令或任何其他命令是否成功执行,只需
检查 $? 执行命令后的值。返回值为 0 表示成功,非零表示失败。

if [ $?=0 ]
then 
 echo "Success"
else
 echo "Failure"
fi