【问题标题】:How to check if the connection to the database was successful?如何检查与数据库的连接是否成功?
【发布时间】:2014-06-23 15:21:00
【问题描述】:

我需要检查数据库连接是否成功。 使用命令

sqlplus <username>/<password>@<SID>

如果连接成功,则命令返回一个标记为 Y/N 或其他值的变量。应该为多个服务器和存储在一个文件中的标志执行此操作。

我不知道如何继续?

【问题讨论】:

标签: sql oracle bash shell


【解决方案1】:

Linux 平台

TWO_TASK=TNS_ALIAS

sqlplus -s /nolog <<!
whenever sqlerror exit 1;
connect user/pass;
select * from dual;
exit
!

if [ $? = 0 ]; then
    echo "success"
else
    echo "failed"
fi

Windows 平台

set local=TNS_ALIAS
@(
   echo whenever sqlerror exit 1^; 
   echo connect user/pass;
   echo select * from dual^;
   echo exit^;
) > %TEMP%\run.sql
sqlplus /nolog @%TEMP%\run.sql

if "%errorlevel%"=="0" cls &echo success.
if "%errorlevel%"=="1" cls &echo failed

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-04-24
    • 2016-12-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多