[20141216]sqlplus的set appinfo.txt

lfree發表於2014-12-16

[20141216]sqlplus的set appinfo.txt

--今天學習了sqlplus的set appinfo命令,可以設定module引數。做一個簡單記錄。

--會話1:
SCOTT@test> @ver
BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production

SCOTT@test> set appinfo test
SCOTT@test> SElect sysdate from dual ;
SYSDATE
-------------------
2014-12-16 16:07:08

SCOTT@test> select * from dept where rownum<=1;
    DEPTNO DNAME          LOC
---------- -------------- -------------
        10 ACCOUNTING     NEW YORK

--在另外的會話執行,會話2:
SCOTT@test> select sql_id,sql_text,child_number,executions,buffer_gets from v$sql where module='test';
SQL_ID        SQL_TEXT                                                     CHILD_NUMBER EXECUTIONS BUFFER_GETS
------------- ------------------------------------------------------------ ------------ ---------- -----------
20zmcgcrnnrxs SElect sysdate from dual                                                0          1           0
cf2xz73hgrf81 select * from dept where rownum<=1                                      0          1          64

--這樣可以定位知道執行語句的sql_id.注意module的大小寫。

SCOTT@test> select * from emp where rownum<=1;
     EMPNO ENAME      JOB              MGR HIREDATE                   SAL       COMM     DEPTNO
---------- ---------- --------- ---------- ------------------- ---------- ---------- ----------
      7369 SMITH      CLERK           7902 1980-12-17 00:00:00        800                    20

--會話1執行:
SCOTT@test> select * from emp where rownum<=1;
     EMPNO ENAME      JOB              MGR HIREDATE                   SAL       COMM     DEPTNO
---------- ---------- --------- ---------- ------------------- ---------- ---------- ----------
      7369 SMITH      CLERK           7902 1980-12-17 00:00:00        800                    20

--會話2執行:
SCOTT@test> select sql_id,sql_text,child_number,executions,buffer_gets from v$sql where module='test';
SQL_ID        SQL_TEXT                                                     CHILD_NUMBER EXECUTIONS BUFFER_GETS
------------- ------------------------------------------------------------ ------------ ---------- -----------
20zmcgcrnnrxs SElect sysdate from dual                                                0          1           0
cf2xz73hgrf81 select * from dept where rownum<=1                                      0          1          64

--看不到執行的select * from emp where rownum<=1;語句,這個因為別的會話已經執行。只要把語句寫的特殊一些,比如加入註解或者
--改變大小寫就ok了。

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/267265/viewspace-1369832/,如需轉載,請註明出處,否則將追究法律責任。

相關文章