?????????Linux/Unix Shell ??SQL ???????????????????????DBA?????Ч??????????Linux/Unix shell sql ???????????????????????????ο???

????Linux/Unix ?μ???SQL??RAMN ??ο???Linux/Unix shell ????е???SQL??RMAN???

??????????

????1??shell????????sql??????????

oracle@SZDB:~> more ./retval.sh
#!/bin/bash
RETVAL=`sqlplus -silent scott/tiger <<EOF
SET PAGESIZE 0 FEEDBACK OFF VERIFY OFF HEADING OFF ECHO OFF
SELECT * FROM emp WHERE ename='SCOTT';
EXIT;
EOF`
if [ -z "$RETVAL" ]; then
  echo "No rows returned from database"
  exit 0
else
  echo $RETVAL
fi

oracle@SZDB:~> chmod u+x retval.sh
oracle@SZDB:~> ./retval.sh
7788 SCOTT ANALYST 7566 19-APR-87 34171.88 20

????2??shell????????sql???????????

oracle@SZDB:~> more ./retval_2.sh
#!/bin/bash
# Author : Robinson Cheng
# Blog   : http://blog.csdn.net/robinson_0612
sqlplus -S "scott/tiger" <<EOF
SET PAGESIZE 0 FEEDBACK OFF VERIFY OFF HEADING OFF ECHO OFF
col cnt new_value v_cnt
SELECT count(*) cnt FROM emp WHERE deptno=10;
exit v_cnt
EOF
VALUE="$?"
echo "show rows for deptno 10:$VALUE"

????3????shell????????????????sql???

oracle@SZDB:~> more ./retval_3.sh
#!/bin/bash
v_empno="$1"
sqlplus -S "scott/tiger" <<EOF
SET PAGESIZE 0 FEEDBACK OFF VERIFY OFF HEADING OFF ECHO OFF
SELECT ename FROM emp WHERE empno=$v_empno;
exit
EOF
exit

oracle@SZDB:~> ./retval_3.sh 7788
SCOTT