溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

如何獲取完整的sqltext腳本

發(fā)布時(shí)間:2021-11-12 09:47:25 來源:億速云 閱讀:276 作者:小新 欄目:關(guān)系型數(shù)據(jù)庫(kù)

這篇文章給大家分享的是有關(guān)如何獲取完整的sqltext腳本的內(nèi)容。小編覺得挺實(shí)用的,因此分享給大家做個(gè)參考,一起跟隨小編過來看看吧。

#!/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 "then type of parameter only are HIST or MOMERY!!"

fi

感謝各位的閱讀!關(guān)于“如何獲取完整的sqltext腳本”這篇文章就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,讓大家可以學(xué)到更多知識(shí),如果覺得文章不錯(cuò),可以把它分享出去讓更多的人看到吧!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI