iis服务器助手广告广告
返回顶部
首页 > 资讯 > 数据库 >[20211126]完善tpt pr.sql脚本.txt
  • 882
分享到

[20211126]完善tpt pr.sql脚本.txt

[20211126]完善tptpr.sql脚本.txt 2015-03-12 14:03:16 882人浏览 无得
摘要

[20211126]完善tpt pr.sql脚本.txt--//tpt提供pr.sql脚本把原来横向输出的内容变成纵向输出,便于阅读。但是有一个小问题,通过例子说明:1.环境:SCOTT@book> @ ver1PORT_STRING  

[20211126]完善tpt pr.sql脚本.txt

[20211126]完善tpt pr.sql脚本.txt

--//tpt提供pr.sql脚本把原来横向输出的内容变成纵向输出,便于阅读。但是有一个小问题,通过例子说明:

1.环境:
SCOTT@book> @ ver1
PORT_STRING                    VERSioN        BANNER
------------------------------ -------------- --------------------------------------------------------------------------------
x86_64/linux 2.4.xx            11.2.0.4.0     oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production

2.测试
SCOTT@book> @ spid
       SID    SERIAL# PROCESS                  SERVER    SPID       PID  P_SERIAL# C50
---------- ---------- ------------------------ --------- ------ ------- ---------- --------------------------------------------------
        44       1574 35220                    DEDICATED 35221       27        146 alter system kill session "44,1574" immediate;

SCOTT@book> @ usid 44
USERNAME                SID                 AUDSID OSUSER           MacHINE            PROGRAM              SPID             OPID CPID                     SQL_ID         HASH_VALUE   LASTCALL STATUS   SADDR            PADDR            TADDR
----------------------- -------------- ----------- ---------------- ------------------ -------------------- -------------- ------ ------------------------ ------------- ----------- ---------- -------- ---------------- ---------------- ----------------
LOGoN_TIME
-------------------
SCOTT                    "44,1574"        18290945 oracle           xxxxxxdg4           (TNS V1-V3)          35221              27 35220                    9r6m4c0hpg6dx   559389117          0 ACTIVE   000000008638EC10 000000008620F338
2021-11-26 11:12:29

--//输出内容太多换行了。

SCOTT@book> @ pr
ERROR:
ORA-01756: quoted string not properly terminated

--//出现ora-01756错误。检查pr.sql脚本,发现使用字符作为分隔。
0 c clob := q"
0 declare

999999      ";;

$ grep "\" usid.sql
       substr(s.machine,instr(s.machine,"")) u_machine,
--//而usid脚本里面正好也有字符.这样导致分隔报错。这样修改pr.sql选择一个不常用的字符作为分隔就ok了。选择那个呢?
--//实际上任何可见的字符都可能出现问题,很简单选择一个不可见字符ctrl+g(小喇叭发生声音,一般代码不会出现)或者ctrl+f作为分隔.
--//在linux 的vim下通过ctrl+v ctrl+f输入。

SCOTT@book> @ pr
PL/SQL procedure successfully completed.

--//嗯,没有输出。查看代码可以发现usid.sql脚本里面有&1要替换,修改如下执行:

SCOTT@book> @ pr 44
==============================
U_USERNAME                    : SCOTT
U_SID                         :  "44,1574"
U_AUDSID                      : 18290945
U_OSUSER                      : oracle
U_MACHINE                     : xxxxxxdg4
U_PROGRAM                     : (TNS V1-V3)
U_SPID                        : 35221
U_PID                         : 27
CPID                          : 35220
SQL_ID                        : 2jwdj6msnrx81
USID_SQL_HASH_VALUE           : 4048286977
LASTCALL                      : 0
STATUS                        : ACTIVE
SADDR                         : 000000008638EC10
PADDR                         : 000000008620F338
TADDR                         :
LOGON_TIME                    : 2021-11-26 11:12:29
PL/SQL procedure successfully completed.

--//OK。

$ cat -vs pr.sql
.
-- Notes:   This script is based on Tom Kyte"s original printtbl code ( Http://asktom.oracle.com )
--          For coding simplicity (read: lazyness) I"m using custom quotation marks ( q" ) so
--          this script works only from Oracle 10gR2 onwards

def _pr_tmpfile=&_tpt_tempdir/pr_&_tpt_tempfile..tmp

@@saveset
set serverout on size 1000000 termout off
save &_pr_tmpfile replace
set termout on

0 c clob := q"^F
0 declare

999999      ^F";;
999999      l_theCursor     integer default dbms_sql.open_cursor;;
999999      l_columnValue   varchar2(4000);;
999999      l_status        integer;;
999999      l_descTbl       dbms_sql.desc_tab;;
999999      l_colCnt        number;;
999999  begin
999999      dbms_sql.parse(  l_theCursor, c, dbms_sql.native );;
999999      dbms_sql.describe_columns( l_theCursor, l_colCnt, l_descTbl );;
999999      for i in 1 .. l_colCnt loop
999999          dbms_sql.define_column( l_theCursor, i,
999999                                  l_columnValue, 4000 );;
999999      end loop;;
999999      l_status := dbms_sql.execute(l_theCursor);;
999999      while ( dbms_sql.fetch_rows(l_theCursor) > 0 ) loop
999999          dbms_output.put_line( "==============================" );;
999999          for i in 1 .. l_colCnt loop
999999                  dbms_sql.column_value( l_theCursor, i,
999999                                         l_columnValue );;
999999                  dbms_output.put_line
999999                      ( rpad( l_descTbl(i).col_name,
999999                        30 ) || ": " || l_columnValue );;
999999          end loop;;
999999      end loop;;
999999  exception
999999      when others then
999999          dbms_output.put_line(dbms_utility.fORMat_error_backtrace);;
999999          raise;;
999999 end;;
/

@@loadset

get &_pr_tmpfile nolist
host &_delete &_pr_tmpfile

--//注意开头的. 可不是多余的。




您可能感兴趣的文档:

--结束END--

本文标题: [20211126]完善tpt pr.sql脚本.txt

本文链接: https://www.lsjlt.com/news/8949.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • 怎么写出安全的、基本功能完善的Bash脚本
    这篇文章主要为大家分析了怎么写出安全的、基本功能完善的Bash脚本的相关知识点,内容详细易懂,操作细节合理,具有一定参考价值。如果感兴趣的话,不妨跟着跟随小编一起来看看,下面跟着小编一起深入学习“怎么写出安全的、基本功能完善的Bash脚本”...
    99+
    2023-06-28
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作