天天看點

[20120106]使用bash shell顯示隐含參數.txt

我個人喜歡使用putty打開兩個視窗,一個執行sql語句,另外一個檢視目錄user_dump_dest下的trc檔案。

如果要查詢隐含參數,往往要切換sys使用者,執行一個腳本:

$ cat hide.sql

col name format a36

col description format a66

col session_value format a22

col default_value format a22

col system_value format a22

select

   a.ksppinm  name,

   a.ksppdesc DESCRIPTION,

   b.ksppstdf DEFAULT_VALUE,

   b.ksppstvl SESSION_VALUE,

   c.ksppstvl SYSTEM_VALUE

from sys.x$ksppi a, sys.x$ksppcv b, sys.x$ksppsv c

where a.indx = b.indx

 and a.indx = c.indx

 and a.ksppinm like '%&1%'

order by 1;

這樣操作比較麻煩,今天寫了一個shell函數,放在.bash_profile檔案中,内容如下:

P() {

echo '  '

if [ -z "$1" ]; then

sqlplus -S "/ as sysdba" set echo off lin 9999 trimsp on feedb off head on pages 0 newp 0 tab off

col name for a36

col description format a76

col default_value format a10

col session_value format a20

col system_value format a20

select a.ksppinm name, a.ksppdesc DESCRIPTION, b.ksppstdf DEFAULT_VALUE, b.ksppstvl SESSION_VALUE, c.ksppstvl SYSTEM_VALUE from sys.x\$ksppi a, sys.x\$ksppcv b, sys.x\$ksppsv c where a.indx = b.indx and a.indx = c.indx and upper(a.ksppinm) like upper('%$1%') order by 1;

EOF

else

fi

}

這樣直接在shell調用就可以了。注意是大寫的P,這樣避免與其他指令沖突。另外我後面加入grep過濾,實際上是多餘的,主要我定義grep的彩色顯示參數,這樣顯示效果要好一些!

$ env | grep -i grep

GREP_COLOR='01;32'

GREP_OPTIONS='--color=auto'

$ P rowsource

NAME                                DESCRIPTION                                                                            DEFAULT_VALU SESSION_VALU SYSTEM_VALUE

----------------------------------- -------------------------------------------------------------------------------------- ------------ ------------ ------------

_rowsource_execution_statistics     if TRUE, Oracle will collect rowsource statistics                                      TRUE         FALSE        FALSE

_rowsource_profiling_statistics     if TRUE, Oracle will capture active row sources in v$active_session_history            TRUE         TRUE         TRUE

_rowsource_statistics_sampfreq      frequency of rowsource statistic sampling (must be a power of 2)                       TRUE         128          128