UNIX代码:
#!/bin/sh
if [ $# -gt 0 ]
then
## Checking wheather or all the Server Objects are up and working
if [[ $1 = 'PreCheck' ]];then
COUNT_SERV=`${ORACLE_HOME}/bin/sqlplus ${dbConnect} <<GETCOUNT|tee -a ${logFile}
SET HEADING ON
SET SERVEROUTPUT ON SIZE 10000
SET ECHO OFF
SET FEEDBACK OFF
@PLSQLBLCK1.sql
GETCOUNT`
fi
fi
exit 0;
SQL代码:
DECLARE
COUNT_SERV INTEGER;
BEGIN
DBMS_OUTPUT.ENABLE(1000000);
SELECT COUNT (*) INTO COUNT_SERV FROM FT_LM_SERVERS WHERE STATE <> 'START';
IF COUNT_SERV > 0 THEN
DBMS_OUTPUT.PUT_LINE('******ERROR1: One or More BG Object is Down, please restart the BG to proceed ahead******');
END IF;
END;
我正在尝试获取存储在(UNIX的)COUNT_SERV中的DBMS_OUTPUT.PUT_LINE的值,以便可以在前面相应地使用它。但是,如果执行shell脚本,则会在日志文件中获得如下输出:
SQL> SQL> SQL> SQL> SQL> SQL> SQL> 18 19 20
如果某些值被隐藏,请忽略,因为我无法在此处显示完整的代码。
您的代码中有一些错误:
-S
参数用于SQL * PlusGETCOUNT
放在第一列中...然后代码将起作用,例如:]]
test.sql:
BEGIN DBMS_OUTPUT.PUT_LINE('foobar'); END; / -- <-- Slash!!!
test.sh
foo=`./sqlplus -S foo/bar@bla <<EOF | tee -a logfile SET HEADING ON; SET SERVEROUTPUT ON SIZE 10000; SET ECHO OFF; SET FEEDBACK OFF; @test.sql; EOF` # <-- First column!!!
cat logfile --> foobar