如果在Sqlplus中使用綁定變量

如果在Sqlplus中使用綁定變量,直接上案例:

spid=`ps -e -o pcpu -o pid -o user -o args | grep oracle | sort -n -k 1| tail -10 | awk '{print $2}'`
for i in $spid
do
sqlplus  /nolog << EOF
conn / as sysdba
set feedback off
set linesize 200
set pagesize 70
column spid format 99999
column sid format 99999
column module format a20
column username format a8
column sql_text format a60
variable spid number;
exec :spid :=$i;
select distinct c.spid, b.sid, b.username, a.module, a.hash_value, sql_text
  from v\$sql a, v\$session b, v\$process c
 where a.hash_value = b.sql_hash_value
   and a.address = b.sql_address
   and b.paddr = c.addr
   and c.spid = :spid;
exit
EOF
done

variable spid number;
exec :spid :=$i;

聲明變量spid , 用spid接收參數,再把spid做爲綁定變量使用

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章