[20211026]奇怪註解不起作用.txt
[20211026]奇怪註解不起作用.txt
--//昨天在測試row cache 相關等待時,我發現我指令碼里面的註解不起作用為什麼,今天仔細探究看看。
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.測試環境建立:
$ cat m14.txt
set verify off
host sleep $(echo &&3/50 | bc -l )
variable vmethod varchar2(20);
exec :vmethod := '&&2';
insert into job_times values ( sys_context ('userenv', 'sid') ,dbms_utility.get_time ,:vmethod) ;
commit ;
declare
v_id number;
v_d date;
v_val VARCHAR2(1000);
l_count PLS_INTEGER;
begin
for i in 1 .. &&1 loop
--//select value into v_val from v$nls_parameters where parameter = 'NLS_CHARACTERSET';
--//select value into v_val from nls_database_parameters where parameter = 'NLS_CHARACTERSET';
--//select sql_text into v_val from v$sql where rownum=1;
SELECT /* &&3 */ seq1.NEXTVAL into v_id FROM DUAL;
end loop;
end ;
/
update job_times set time_ela = dbms_utility.get_time - time_ela where sid=sys_context ('userenv', 'sid') and method=:vmethod;
commit;
quit
--//說明:迴圈體內指令碼SELECT /* &&3 */ seq1.NEXTVAL into v_id FROM DUAL;.
3.測試:
SCOTT@book> @ tpt/sql_id 9cp836a3k67w2 %
Show SQL text, child cursors and execution stats for SQLID 9cp836a3k67w2 child %
no rows selected
no rows selected
--//可以發現測試前該語句不再共享池中。
SCOTT@book> @m14.txt 100 P=1 1
PL/SQL procedure successfully completed.
1 row created.
Commit complete.
PL/SQL procedure successfully completed.
1 row updated.
Commit complete.
SCOTT@book> @ tpt/sql_id 9cp836a3k67w2 %
Show SQL text, child cursors and execution stats for SQLID 9cp836a3k67w2 child %
HASH_VALUE CH# SQL_TEXT
---------- ---- ------------------------------
2267225986 0 SELECT SEQ1.NEXTVAL FROM DUAL
CH# PARENT_HANDLE OBJECT_HANDLE PLAN_HASH PARSES H_PARSES EXECUTIONS FETCHES ROWS_PROCESSED CPU_MS ELA_MS LIOS PIOS SORTS USERS_EXECUTING
---- ---------------- ---------------- ---------- ---------- ---------- ---------- ---------- -------------- ---------- ---------- ---------- ---------- ---------- ---------------
0 000000007C3DCAB8 000000007CAB3C68 51561390 1 1 100 100 100 20.997 19.969 404 0 0 0
--//執行的是SELECT SEQ1.NEXTVAL FROM DUAL,oracle的PLSQL指令碼把我寫的註解給丟失了。
SCOTT@book> select sql_id,executions,sql_fulltext c200 from v$sqlarea where lower(sql_text) like '%seq1.nextval%';
SQL_ID EXECUTIONS C200
------------- ---------- -------------------------------------------------------------------------------------------------------
gspuskkd102p6 1 select sql_text from v$sqlarea where lower(sql_text) like '%seq1.nextval%'
d6dgq30k5jb64 1 declare
v_id number;
v_d date;
v_val VARCHAR2(1000);
l_count PLS_INTEGER;
begin
for i in 1 .. 100 loop
--//select value into v_val from v$nls_parameters where parameter = 'NLS_CHARACTERSET';
--//select value into v_val from nls_database_parameters where parameter = 'NLS_CHARACTERSET';
--//select sql_text into v_val from v$sql where rownum=1;
SELECT /* 1 */ seq1.NEXTVAL into v_id FROM DUAL;
end loop;
end ;
f7tupa89262a0 1 select sql_id,sql_fulltext from v$sqlarea where lower(sql_text) like '%seq1.nextval%'
9cp836a3k67w2 100 SELECT SEQ1.NEXTVAL FROM DUAL
--//仔細看sql_id=d6dgq30k5jb64,裡面的語句帶註解的,而sql_id=9cp836a3k67w2時,註解不見了。
--//修改為註解裡面多了一個加號。
SELECT /*+ &&3 */ seq1.NEXTVAL into v_id FROM DUAL;
SCOTT@book> @ m14.txt 100 test 2
PL/SQL procedure successfully completed.
1 row created.
Commit complete.
PL/SQL procedure successfully completed.
1 row updated.
Commit complete.
SCOTT@book> select sql_id,executions,sql_fulltext c200 from v$sqlarea where lower(sql_text) like '%seq1.nextval%' and executions>=99;
SQL_ID EXECUTIONS C200
------------- ---------- --------------------------------------
bd62h0wujsfms 100 SELECT /*+ 2 */ SEQ1.NEXTVAL FROM DUAL
9cp836a3k67w2 100 SELECT SEQ1.NEXTVAL FROM DUAL
--//注意看這回註解起作用了,大家可以注意一個細節PLSQL會全部轉化為大寫。oracle有時候真搞不懂。
--//看看其它語句的情況:
set verify off
host sleep $(echo &&3/50 | bc -l )
variable vmethod varchar2(20);
exec :vmethod := '&&2';
insert into job_times values ( sys_context ('userenv', 'sid') ,dbms_utility.get_time ,:vmethod) ;
commit ;
declare
v_id number;
v_d date;
v_val VARCHAR2(1000);
l_count PLS_INTEGER;
begin
for i in 1 .. &&1 loop
--//select value into v_val from v$nls_parameters where parameter = 'NLS_CHARACTERSET';
select /* &&3 */ value into v_val from nls_database_parameters where parameter = 'NLS_CHARACTERSET';
--//select sql_text into v_val from v$sql where rownum=1;
--//SELECT /*+ &&3 */ seq1.NEXTVAL into v_id FROM DUAL;
end loop;
end ;
/
update job_times set time_ela = dbms_utility.get_time - time_ela where sid=sys_context ('userenv', 'sid') and method=:vmethod;
commit;
--//quit
SCOTT@book> @ m14.txt 300 PPP 3
PL/SQL procedure successfully completed.
1 row created.
Commit complete.
PL/SQL procedure successfully completed.
2 rows updated.
Commit complete.
SCOTT@book> select sql_id,executions,sql_fulltext c200 from v$sqlarea where lower(sql_text) like '%nls%' and executions>=299;
SQL_ID EXECUTIONS C200
------------- ---------- ------------------------------------------------------------------------------
7mgsfc44trnr8 300 SELECT VALUE FROM NLS_DATABASE_PARAMETERS WHERE PARAMETER = 'NLS_CHARACTERSET'
--//註解丟失。迴圈體內改為如下呢?
select /* &&3 */deptno into v_id from dept where deptno=10;
SCOTT@book> @ m14.txt 400 OOO 4
SCOTT@book> select sql_id,executions,sql_fulltext c200 from v$sqlarea where lower(sql_text) like '%deptno%' and executions>=299;
SQL_ID EXECUTIONS C200
------------- ---------- ---------------------------------------
a31kd5tkdvvmm 400 SELECT DEPTNO FROM DEPT WHERE DEPTNO=10
--//確實如此,以後測試中注意這個細節問題,註解裡面加入+,PLSQL才不會取消註解內容。
4.補充測試:
--//如果語句在sqlplus直接執行這樣沒有加號的註解是有效的。
SCOTT@book> select /* 1 */ * from dept where deptno=20;
DEPTNO DNAME LOC
---------- -------------- -------------
20 RESEARCH DALLAS
SCOTT@book> @ dpc '' ''
PLAN_TABLE_OUTPUT
-------------------------------------
SQL_ID 41uk0b87mb1zq, child number 0
-------------------------------------
select /* 1 */ * from dept where deptno=20
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Plan hash value: 2852011669
----------------------------------------------------------------------------------------
| Id | Operation | Name | E-Rows |E-Bytes| Cost (%CPU)| E-Time |
----------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | | | 1 (100)| |
| 1 | TABLE ACCESS BY INDEX ROWID| DEPT | 1 | 20 | 1 (0)| 00:00:01 |
|* 2 | INDEX UNIQUE SCAN | PK_DEPT | 1 | | 0 (0)| |
----------------------------------------------------------------------------------------
Query Block Name / Object Alias (identified by operation id):
-------------------------------------------------------------
1 - SEL$1 / DEPT@SEL$1
2 - SEL$1 / DEPT@SEL$1
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("DEPTNO"=20)
--//注意看下劃線註解並沒有消失。
--//總之以後測試工作注意這個細節問題。
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/267265/viewspace-2839284/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- [20211026]關於18c row cache mutex.txtMutex
- [20230905]奇怪的語法.txt
- [20210120]提示加入註解.txt
- [20221020]奇怪的增量備份.txt
- [20220822]奇怪的ashtop輸出.txt
- [20211111]奇怪的ashtop輸出.txt
- [20210802]grep奇怪的過濾.txt
- [20211020]奇怪lsnrctl status顯示.txt
- [20210924]awk奇怪的輸出.txt
- [20201106]奇怪的awr報表.txt
- [20181120]奇怪的insert語句.txt
- [20231012]奇怪的執行時長.txt
- [20230426]奇怪的AVG_IOW_MS.txt
- [20190306]奇怪的查詢結果.txt
- [20221103]奇怪的mail資訊(整理版本).txtAI
- [20211018]奇怪的歸檔目的地.txt
- [20210924]awk奇怪的輸出2.txt
- [20211210]優化遇到的奇怪問題.txt優化
- [20180417]奇怪的grep過濾問題.txt
- [20240826]奇怪ORA-01031 insufficient privileges報錯.txt
- [20231124]奇怪的高邏輯讀4.txt
- [20230405]奇怪的顯示輸出寬度.txt
- [20230216]奇怪的高邏輯讀3.txt
- [20220811]奇怪的隱式轉換問題.txt
- [20190324]奇怪的GV$FILESPACE_USAGE檢視.txt
- [20210420]19c奇怪的過濾條件.txt
- [20181201]奇怪的INDEX SKIP SCAN執行計劃.txtIndex
- [20240607]PL/SQL中sql語句的註解.txtSQL
- [20211209]pdb資料庫kill job遇到的奇怪情況.txt資料庫
- 奇怪的漢諾塔 - 題解
- Failed to execute aapt的奇怪解決方法AIAPT
- [20211214]檢視檢視V$ACTIVE_SESSION_HISTORY遇到奇怪問題.txtSession
- JAVA-註解(2)-自定義註解及反射註解Java反射
- 註解專題(一)Java元註解,內建註解Java
- [20220815]奇怪的隱式轉換問題(11g測試補充).txt
- [20220811]奇怪的隱式轉換問題(12c補充測試).txt
- .gitignore 不起作用Git
- Java註解-後設資料、註解分類、內建註解和自定義註解Java