有时候我们可能会需要在Shell脚本中执行SELECT语句,并将结果赋值给一个变量,对于这样的情形,我们可以用以下的方法来达到目的。#!/bin/ksh # # Created : 2015.05.25 # Updated : 2015.05.25 # Author : Jet Chenxi Zhang # Description : Get SELECT result in Shell# Variable Definitions # Oracle_SID=audtest ORACLE_HOME=/app/oracle/product/database/11.2.0/db_1 PATH=$PATH:$ORACLE_HOME/bin DBNAME=
# Get Database name by quering v$database # DBNMAE=` sqlplus -s /nolog <<EOF set echo off feedback off heading off underline off; conn / as sysdba; select name from v\$database; exit; EOF`
# Get Database name by quering v$database # QUERYRES=` sqlplus -s /nolog <<EOF set echo off feedback off heading off underline off; conn / as sysdba; select dbid, name from v\$database; exit; EOF`