尝试在UNIX变量中存储PL / SQL块的值

问题描述 投票:1回答:1

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  

如果某些值被隐藏,请忽略,因为我无法在此处显示完整的代码。

shell unix plsql sh plsqldeveloper
1个回答
0
投票

您的代码中有一些错误:

  • -S参数用于SQL * Plus
  • 在PL / SQL块末尾加上斜线
  • 将结尾GETCOUNT放在第一列中

...然后代码将起作用,例如:]]

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

© www.soinside.com 2019 - 2024. All rights reserved.