#!/usr/bin/ksh # set -xv SBINS=$SBIN/scripts HOST=`hostname` HOST=`echo $HOST | awk '{ printf ("%-+15.15s",$1) }'` # Modified : 17 Jun 2009 Added the get_hash_Value function # ...................................................................................................... function help { cat < # show the sql statement st -f # Format SQL statement (SELECT only) st -sgen # sql text + fetch & initialize binds from v\\$sql_bind_capture st -lb # show bind variable sample (10g)+ EOF exit } # ...................................................................................................... function get_min_child { ret=`sqlplus -s "$CONNECT_STRING" </dev/null echo "rem F_USER=$F_USER" SQL=`sqlplus -s "$CONNECT_STRING" < $FOUT echo "File : $FOUT" echo "$VAR" | sed -e 's@|@@' -e 's@\(.*\)|$@\1@' -e 's@| |@@g' -e 's/[^a-zA-Z0-0_][wW][hH][eE][rR][eE][^a-zA-Z0-0_]/\ WHERE \ /g' -e 's/[^a-zA-Z0-0_]*[sS][eE][lL][eE][cC][tT][^a-zA-Z0-0_]/\ SELECT \ /g' -e 's/[^a-zA-Z0-0_][fF][rR][oO][mM][^a-zA-Z0-0_]/\ FROM \ /g' -e 's/ [aA][nN][dD] /\ AND /g' -e 's/ [oO][rR][dD][eE][rR] [bB][yY] /\ ORDER BY /g' -e 's/ [gG][rR][oO][uU][pP] [bB][yY] /\ GROUP BY /g' -e 's/[sS][eE][tT][^a-zA-Z0-0_]/\ SET /g' -e 's/[^a-zA-Z0-0_][cC][aA][sS][Ee][^a-zA-Z0-0_]/\ CASE /g' -e 's/[^a-zA-Z0-0_][wW][hH][eE][nN][^a-zA-Z0-0_]/\ WHEN /g' -e 's/,\([^,][^,]*\),\([^,][^,]*\),\([^,][^,]*\),/,\1,\2,\3,\ /g' # ------------------------------------------------------------- elif [ -n "$SQL_ID" ];then TITTLE='get sql text' SQL=" set heading on set linesize 132 pagesize 0 col HASH_VALUE format 999999999 col sql_text format A4000 break on sql_text prompt prompt . Type sq -hv $HASH_VALUE to see stats on this sql prompt select regexp_replace( max(sys_connect_by_path (sql_text,'{') ), '{','') sql_text from ( select piece, sql_text from v\$sqltext_with_newlines where sql_id='$sql_id' order by 1 ) start with piece=0 connect by piece = prior piece + 1 / select sid from v\$session where sql_id = '$SQL_ID' or prev_sql_id = '$SQL_ID' / " # ------------------------------------------------------------- else TITTLE='get sql text' SQL=" set heading on set linesize 132 pagesize 0 col HASH_VALUE format 999999999 col sql_text format A4000 break on sql_text prompt prompt . Type sq -hv $HASH_VALUE to see stats on this sql prompt select regexp_replace( max(sys_connect_by_path (sql_text,'{') ), '{','') sql_text from ( select piece, sql_text from v\$sqltext_with_newlines where HASH_VALUE=$HASH_VALUE order by 1 ) start with piece=0 connect by piece = prior piece + 1 / select sid from v\$session where sql_hash_value = $HASH_VALUE or prev_hash_value = $HASH_VALUE / " fi # ................................ # we do the job here # ................................ do_sql