重庆分公司,新征程启航

为企业提供网站建设、域名注册、服务器等服务

获取sql完整脚本,get_fulltext.sh

点击(此处)折叠或打开

网站建设公司,为您提供网站建设,网站制作,网页设计及定制网站建设服务,专注于成都定制网页设计,高端网页制作,对成都公路钻孔机等多个行业拥有丰富的网站建设经验的网站建设公司。专业网站设计,网站优化推广哪家好,专业成都网站推广优化,H5建站,响应式网站。

  1. #!/bin/bash
  2. # by ray
  3. # 2017-08-31
  4. #v0.1

  5. ##get sqltext from dbs_hist_sqltext,sqltext will be save current directory and file name will be sql_id.txt
  6. FromHist(){
  7. sqlplus -s /nolog <<-RAY
  8.     conn / as sysdba
  9.     set linesize 300
  10.     set serveroutput on
  11.     set feedback off
  12.     spool ./$1.txt
  13.     declare
  14.     l_buffer varchar2(3000);
  15.     l_amount binary_integer :=3000;
  16.     l_pos int :=1;
  17.     l_clob_length int;
  18.     sqlid varchar2(100) := '$1';
  19.     begin
  20.     select DBMS_LOB.getlength(sql_text) into l_clob_length from dba_hist_sqltext where sql_id=sqlid;
  21.     while l_pos
  22.     select DBMS_LOB.SUBSTR(sql_text,l_amount,l_pos) into l_buffer from dba_hist_sqltext where sql_id=sqlid;
  23.     dbms_output.put(l_buffer);
  24.     l_pos:=l_pos+l_amount;
  25.     end loop;
  26.     dbms_output.put_line(' ');
  27.     end;
  28.     /
  29.     spool off
  30.     exit
  31. RAY
  32. }


  33. ##get sqltext from V$sqlarea,sqltext will be save current directory and file name will be sql_id.txt
  34. FromMomery(){
  35. sqlplus -s /nolog <<-RAY
  36.     conn / as sysdba
  37.     set linesize 300
  38.     set serveroutput on
  39.     set feedback off
  40.     spool ./$1.txt
  41.     declare
  42.     l_buffer varchar2(3000);
  43.     l_amount binary_integer :=3000;
  44.     l_pos int :=1;
  45.     l_clob_length int;
  46.     sqlid varchar2(100) := '$1';
  47.     begin
  48.     select DBMS_LOB.getlength(sql_fulltext) into l_clob_length from v\$sqlarea where sql_id=sqlid;
  49.     while l_pos
  50.     select DBMS_LOB.SUBSTR(sql_fulltext,l_amount,l_pos) into l_buffer from v\$sqlarea where sql_id=sqlid;
  51.     dbms_output.put(l_buffer);
  52.     l_pos:=l_pos+l_amount;
  53.     end loop;
  54.     dbms_output.put_line(' ');
  55.     end;
  56.     /
  57.     spool off
  58.     exit
  59. RAY
  60. }

  61. func_help(){
  62.     echo "--from specifying how to get sqltext,memery or hist can be used.default momery!!"
  63.     echo "--sqlid specify a sql_id"
  64.     echo "for example:"
  65.     echo "get_fulltext.sh --from=momery --sqlid=*********"
  66. }

  67. #get parameter
  68. argvs=($@)
  69. for i in ${argvs[@]}
  70. do
  71.         case `echo $i | awk -F '=' '{print $1}' | awk -F '--' '{print $2}'| tr [a-z] [A-Z]` in
  72.         FROM)
  73.             fm=`echo $i | awk -F '=' '{print $2}' | tr [a-z] [A-Z]`
  74.         ;;
  75.         SQLID)
  76.             sqlid=`echo $i | awk -F '=' '{print $2}' `
  77.         ;;
  78.         HELP)
  79.             func_help
  80.             exit 1
  81.         esac
  82. done

  83. if [ ! ${fm} ]; then
  84.     fm='MOMERY'
  85. fi
  86. if [ ! ${sqlid} ]; then
  87.     echo "The sql_id must be specified!!"
  88.     exit 1
  89. fi

  90. ##exec script
  91. if [ ${fm} == "HIST" ];then
  92.     FromHist "${sqlid}"
  93. elif [ ${fm} == "MOMERY" ];then
  94.     FromMomery "${sqlid}"
  95. else
  96.     echo "The type of parameter only are HIST or MOMERY!!"
  97. fi


网站栏目:获取sql完整脚本,get_fulltext.sh
URL链接:http://cqcxhl.cn/article/joiehd.html

其他资讯

在线咨询
服务热线
服务热线:028-86922220
TOP