如何将 SQLPLUS 输出值分配给根变量

如何将 SQLPLUS 输出值分配给根变量

我正在尝试使用以下函数作为 root 用户将 sqlplus 输出分配给 unix 变量

function sql {
su - oracle -c "
 export ORACLE_HOME=$( "`grep "OraG" /u01/app/oraInventory/ContentsXML/inventory.xml | awk '{print $3}'|  cut -d= -f2 | sed 's/\"//g'`"/bin/crsctl status resource -w "((TYPE = ora.database.type) AND (LAST_SERVER = $(hostname -s)))" -f | grep ^ORACLE_HOME= | awk -F= '{ print $2 }' )

   export ORACLE_SID=$( "`grep "OraG" /u01/app/oraInventory/ContentsXML/inventory.xml | awk '{print $3}'|  cut -d= -f2 | sed 's/\"//g'`"/bin/crsctl status resource -w "((TYPE = ora.database.type) AND (LAST_SERVER = $(hostname -s)))" -f | grep ^USR_ORA_INST_NAME= | awk -F= '{ print $2 }' )

   export PATH=$PATH:$ORACLE_HOME/bin

   SQL_OUTPUT=$( $ORACLE_HOME/bin/sqlplus -s / as sysdba<< OCI2
   connect / as sysdba
   set heading off
   set feedback off
   set linesize 145
   set linesize 145
   set feedback off
   spool /tmp/sqlplus.log
   $1
   spool off
   exit
OCI2
   )
   echo "$SQL_OUTPUT"| grep -v \^$
"
}

SPFILE=$(sql "select value from v\$parameter where name = 'spfile';")

但出现以下错误

[root@xxxxxx tmp]# SPFILE=$(sql "select value from v\$parameter where name = 'spfile';")
-bash: /bin/sqlplus: No such file or directory

相关内容