我正在尝试创建一个连接到oracle
数据库的简单脚本,执行select查询并将返回值存储到Unix
变量中。以下是我按照this post创建的脚本:
#!/bin/sh
VALUE=`sqlplus -silent $DB_USERNAME/"$PASSWORD"@"(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=$HOST_NAME)(PORT=$DB_PORT)))(CONNECT_DATA=(SID=$DB_SID)))" <<END
set pagesize 0 feedback off verify off heading off echo off
SELECT ID FROM TEST_USERS WHERE USER_NAME=$SAMPLE_USER;
exit;
END`
if [ -z "$VALUE" ]; then
echo "No rows returned from database"
exit 0
else
echo $VALUE
fi
现在,当我运行此脚本时,我面临错误:
错误:ORA-12533:TNS:非法ADDRESS参数SP2-0306:无效 选项。用法:CONN [ECT] [{logon | / | proxy} [AS {SYSDBA | SYSOPER | SYSASM}] [edition = value]]其中:: = [/] [@] :: = [] [/] [@] SP2-0306: 选项无效。用法:CONN [ECT] [{logon | / | proxy} [AS {SYSDBA | SYSOPER | SYSASM}] [edition = value]]其中:: = [/] [@] :: = [] [/] [@] SP2-0157: 3次尝试后无法连接到ORACLE,退出SQL * Plus
请让我知道我在哪里做错了?
答案 0 :(得分:1)
尝试使用此VALUE
变量:
VALUE=`sqlplus $DB_USERNAME/$PASSWORD@//$HOST_NAME:$DB_PORT/$DB_SID`
当然,你需要定义所有变量,你在之前使用这一行