[20210428]改進pr.sql指令碼.txt
[20210428]改進pr.sql指令碼.txt
--//tanel poder提供一個指令碼pr.sql,用來實現顯示資訊的縱向顯示。例子:
SCOTT@book> select * from dept where deptno=10
2 @ pr
Pivoting output using Tom Kyte's printtab....
==============================
DEPTNO : 10
DNAME : ACCOUNTING
LOC : NEW YORK
PL/SQL procedure successfully completed.
--//第一次看到這樣的使用是上網站,不知道對方如何實現的。後來對方給我一個指令碼,好像是windows
--//版本我修改一下,適合linux使用。我這才想起來tanel poder的指令碼包裡面有。
$ cat prxx.sql
.
set termout off
def _pr_tmpfile=/tmp/pr.out
store set &_pr_tmpfile.set replace
set termout on
set serverout on size 1000000 termout off echo off
save &_pr_tmpfile replace
set termout on
0 c clob := q'\
0 declare
999999 \';;
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;;
/
set termout off
@&_pr_tmpfile.set
get &_pr_tmpfile nolist
host rm &_pr_tmpfile
set termout on
--//今天我自己再改一下在每個欄位前面加上序號的功能:
$ cat prxxn.sql
.
set termout off
def _pr_tmpfile=/tmp/pr.out
store set &_pr_tmpfile.set replace
set termout on
set serverout on FORMAT WRAPPED size 1000000 termout off echo off
save &_pr_tmpfile replace
set termout on
0 c clob := q'\
0 declare
999999 \';;
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 (lpad(i,3)||' '|| 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;;
/
set termout off
@&_pr_tmpfile.set
get &_pr_tmpfile nolist
host rm &_pr_tmpfile
set termout on
--//注意第一行的點可不是多餘的,不要刪除。
--//測試如下:
SCOTT@book> select * from emp where rownum=1
2 @ prxxn
==================================
1 EMPNO : 7369
2 ENAME : SMITH
3 JOB : CLERK
4 MGR : 7902
5 HIREDATE : 1980-12-17 00:00:00
6 SAL : 800
7 COMM :
8 DEPTNO : 20
PL/SQL procedure successfully completed.
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/267265/viewspace-2770316/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- [20211126]完善tpt pr.sql指令碼.txtSQL指令碼
- [20221126]tpt pr.sql指令碼執行問題.txtSQL指令碼
- [20210428]AnonHugePages與transparent hugepage.txt
- 如何改進你的指令碼程式指令碼
- [20210428]資料庫連線加密.txt資料庫加密
- shell的引數和指令碼流程改進指令碼
- [20190716]十進位制轉換其他進位制指令碼.txt指令碼
- [20210506]完善tix指令碼.txt指令碼
- [20201202]完善sosi指令碼.txt指令碼
- [20210623]完善清除aud指令碼.txt指令碼
- [20190416]exclusive latch測試指令碼.txt指令碼
- [20231117]完善ashtt.sql指令碼.txtSQL指令碼
- [20200117]ashtop指令碼使用簡介.txt指令碼
- [20190510]快速建立執行指令碼.txt指令碼
- [20190423]oradebug peek測試指令碼.txt指令碼
- [20211230]完善sql_id指令碼.txtSQL指令碼
- [20211122]完善descx.sql指令碼.txtSQL指令碼
- [20211118]mutexprof指令碼使用簡介.txtMutex指令碼
- [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指令碼
- [20231021]生成bbed的執行指令碼.txt指令碼
- [20191111]完善bind_cap.sql指令碼.txtSQL指令碼
- [20220217]完善tpt gts.sql指令碼.txtSQL指令碼
- [20220510]完善tpt expandz.sql指令碼.txtSQL指令碼
- [20211202]完善d_buffer.sql指令碼.txtSQL指令碼
- [20211129]完善tpt tablist.sql指令碼.txtSQL指令碼
- [20211130]完善tpt t.sql指令碼.txtSQL指令碼
- [20211129]完善tpt killi.sql指令碼.txtSQL指令碼
- [20211129]更新dpcawr1.sql指令碼.txtPCASQL指令碼
- [20230414]完善seg2.sql指令碼.txtSQL指令碼
- [20230210]建立完善swcnm.sql指令碼.txtSQL指令碼
- [20221208]完善bind_cap.sql指令碼.txtSQL指令碼