[20240219]建立完善sql_idx.sh脚本.txt
--//再次遇到sql_id的计算问题,该语句已经dba_hist相关视图无法查询.
--//w3wp.exe 程序里面的sql语句脚本带有^M符号(dos文本格式),执行时并不过滤.
--//而我的计算sql_id脚本计算时过滤掉^M符号,导致计算错误.
--//我修改完善如下:(注里面的^M在vim for windows下按ctrl+Q ctrl+M
实现,在vim for linux下按ctrl+V ctrl+M
实现,))
#! /bin/bash
# calcucate sql_text of full_hash_value(16),hash_value(10),sql_id(32).
# argv1 sql statement or sql of text file
# argv2 flag: 0= sql statement 1=sql of text file 2=sql of text file (reservation ^M)
odebug=${ODEBUG:-0}
oflag=${2:-0}
if [ $oflag -eq 0 ]
then
sql_text=${1}'\0'
fi
if [ $oflag -eq 1 ]
then
# sql_text="$( cat $1 | dos2unix | sed '$s/;\s*//')"'\0'
sql_text="$( cat $1 | sed "s/
$//" | sed '$s/;\s*//')"'\0'
fi
if [ $oflag -eq 2 ]
then
sql_text="$( cat $1 | sed '$s/;\s*//')"'\0'
fi
v1=$(echo -e -n "$sql_text" | md5sum | sed 's/ -//' | xxd -r -p | od -t x4 | sed -n -e 's/^0\+ //' -e 's/ //gp' | tr 'a-z' 'A-Z')
v2=${v1:(-16):16}
v3=${v2:(-8):8}
# v2=$(echo "obase=16;ibase=16; $v1 % 10000000000000000" | bc| tr -d '\\\r\n')
# v3=$(echo "obase=10;ibase=16; $v1 % 100000000" | bc| tr -d '\\\r\n')
if [ $odebug -eq 1 ] ; then
echo v1=$v1 v2=$v2 v3=$v3
fi
echo "sql_text = $sql_text"
echo "full_hash_value(16) = $v1 "
echo "hash_value(10) = $(( 16#$v3 )) "
BASE32=($(echo {0..9} {a..z} | tr -d 'eilo'))
res=''
for i in $(echo "obase=32;ibase=16; $v2" | bc| tr -d '\\\r\n')
do
res=${res}${BASE32[$(( 10#$i ))]}
done
echo "sql_id(32) = $(printf "%13s" $res | tr ' ' '0')"
echo "sql_id(32) = $(printf "%013s" $res)"
res1=$(eval $(echo "obase=32;ibase=16; $v2" | bc| tr -d '\\\r\n' | awk 'BEGIN{RS=" +"; printf "echo " }/./{printf "${BASE32[$(( 10#%02d))]}", $1}' ))
echo "sql_id(32) = $(printf "%013s" $res1)"