獲取sql完整指令碼,get_fulltext.sh
點選(此處)摺疊或開啟
-
#!/bin/bash
-
# by ray
-
# 2017-08-31
-
#v0.1
-
-
##get sqltext from dbs_hist_sqltext,sqltext will be save current directory and file name will be sql_id.txt
-
FromHist(){
-
sqlplus -s /nolog <<-RAY
-
conn / as sysdba
-
set linesize 300
-
set serveroutput on
-
set feedback off
-
spool ./$1.txt
-
declare
-
l_buffer varchar2(3000);
-
l_amount binary_integer :=3000;
-
l_pos int :=1;
-
l_clob_length int;
-
sqlid varchar2(100) := '$1';
-
begin
-
select DBMS_LOB.getlength(sql_text) into l_clob_length from dba_hist_sqltext where sql_id=sqlid;
-
while l_pos<l_clob_length loop
-
select DBMS_LOB.SUBSTR(sql_text,l_amount,l_pos) into l_buffer from dba_hist_sqltext where sql_id=sqlid;
-
dbms_output.put(l_buffer);
-
l_pos:=l_pos+l_amount;
-
end loop;
-
dbms_output.put_line(' ');
-
end;
-
/
-
spool off
-
exit
-
RAY
-
}
-
-
-
##get sqltext from V$sqlarea,sqltext will be save current directory and file name will be sql_id.txt
-
FromMomery(){
-
sqlplus -s /nolog <<-RAY
-
conn / as sysdba
-
set linesize 300
-
set serveroutput on
-
set feedback off
-
spool ./$1.txt
-
declare
-
l_buffer varchar2(3000);
-
l_amount binary_integer :=3000;
-
l_pos int :=1;
-
l_clob_length int;
-
sqlid varchar2(100) := '$1';
-
begin
-
select DBMS_LOB.getlength(sql_fulltext) into l_clob_length from v\$sqlarea where sql_id=sqlid;
-
while l_pos<l_clob_length loop
-
select DBMS_LOB.SUBSTR(sql_fulltext,l_amount,l_pos) into l_buffer from v\$sqlarea where sql_id=sqlid;
-
dbms_output.put(l_buffer);
-
l_pos:=l_pos+l_amount;
-
end loop;
-
dbms_output.put_line(' ');
-
end;
-
/
-
spool off
-
exit
-
RAY
-
}
-
-
func_help(){
-
echo "--from specifying how to get sqltext,memery or hist can be used.default momery!!"
-
echo "--sqlid specify a sql_id"
-
echo "for example:"
-
echo "get_fulltext.sh --from=momery --sqlid=*********"
-
}
-
-
#get parameter
-
argvs=($@)
-
for i in ${argvs[@]}
-
do
-
case `echo $i | awk -F '=' '{print $1}' | awk -F '--' '{print $2}'| tr [a-z] [A-Z]` in
-
FROM)
-
fm=`echo $i | awk -F '=' '{print $2}' | tr [a-z] [A-Z]`
-
;;
-
SQLID)
-
sqlid=`echo $i | awk -F '=' '{print $2}' `
-
;;
-
HELP)
-
func_help
-
exit 1
-
esac
-
done
-
-
if [ ! ${fm} ]; then
-
fm='MOMERY'
-
fi
-
if [ ! ${sqlid} ]; then
-
echo "The sql_id must be specified!!"
-
exit 1
-
fi
-
-
##exec script
-
if [ ${fm} == "HIST" ];then
-
FromHist "${sqlid}"
-
elif [ ${fm} == "MOMERY" ];then
-
FromMomery "${sqlid}"
-
else
-
echo "The type of parameter only are HIST or MOMERY!!"
- fi
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/28572479/viewspace-2152081/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- jenkins pipline指令碼 獲取git分支Jenkins指令碼Git
- 常用指令碼:獲取隱含引數指令碼
- shell指令碼獲取函式返回值指令碼函式
- shell指令碼獲取時間格式化指令碼
- Linux c程式中獲取shell指令碼輸出(如獲取system命令輸出)LinuxC程式指令碼
- 【Redis】獲取沒有設定ttl的key指令碼Redis指令碼
- vbs指令碼獲取Am註冊路徑資訊指令碼
- 獲取AWR的指令碼,可以在crontab裡面部署指令碼
- 如何獲取微信的版本號詳解【附完整原始碼】原始碼
- shell指令碼中main函式中$#獲取不到指令碼傳入引數個數淺析指令碼AI函式
- mybatis執行sql指令碼MyBatisSQL指令碼
- SQL SERVER巡檢指令碼SQLServer指令碼
- 在SQL隱碼攻擊中使用DNS獲取資料SQLDNS
- Linux Shell獲取正在執行指令碼的絕對路徑Linux指令碼
- Python指令碼的常見引數獲取和處理方式Python指令碼
- 【SQL】SQL解惑-如何從字串中獲取IP地址SQL字串
- Bash 指令碼例項:獲取符號連結的目標位置指令碼符號
- catalog.sql指令碼介紹SQL指令碼
- sql_trace相關指令碼SQL指令碼
- SQL 的後計算指令碼SQL指令碼
- 【Azure Redis 快取】使用Python程式碼獲取Azure Redis的監控指標值 (含Powershell指令碼方式)Redis快取Python指標指令碼
- 獲取所有域使用者的登陸歷史資訊指令碼指令碼
- 採用lua指令碼獲取mysql、redis資料以及jwt的校驗指令碼MySqlRedisJWT
- Laravel 獲取執行的sql語句LaravelSQL
- 獲取AOSP原始碼原始碼
- [20231117]完善ashtt.sql指令碼.txtSQL指令碼
- django指令碼orm中使用原生sqlDjango指令碼ORMSQL
- [20211230]完善sql_id指令碼.txtSQL指令碼
- [20211122]完善descx.sql指令碼.txtSQL指令碼
- [20221012]完善spsw.sql指令碼.txtSQL指令碼
- [20221010]完善descz.sql指令碼.txtSQL指令碼
- [20221101]完善descz.sql指令碼.txtSQL指令碼
- [20221101]完善gts.sql指令碼.txtSQL指令碼
- [20230203]完善awr.sql指令碼.txtSQL指令碼
- [20230123]完善curheapz.sql指令碼.txtSQL指令碼
- [20210407]完善ti.sql指令碼.txtSQL指令碼
- [20210125]完善hide.sql指令碼.txtIDESQL指令碼
- ASP.NET Core獲取請求完整的UrlASP.NET