12C SQL Translation Framework.txt
[20181013]12C SQL Translation Framework.txt
--//12c提供一個dba改寫sql語句的可能性,實際上10g,11g之前也有一個包DBMS_ADVANCED_REWRITE能實現類似的功能.
--//這種功能實在是一種旁門左道,還是測試看看.
--//不過如果程式存在大量的執行錯誤,一樣會影響效能,導致出現SQL*Net break/reset to client.
--//參考連線:0624使用10035事件跟蹤無法執行的sql語句 =>http://blog.itpub.net/267265/viewspace-2120884/
--//http://www.itpub.net/thread-2061952-1-1.html
1.環境:
SCOTT@test01p> @ ver1
PORT_STRING VERSION BANNER CON_ID
------------------------------ -------------- -------------------------------------------------------------------------------- ----------
IBMPC/WIN_NT64-9.1.0 12.2.0.1.0 Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production 0
2.測試:
begin
dbms_sql_translator.create_profile('test_profile');
dbms_sql_translator.register_sql_translation( profile_name => 'test_profile',
sql_text => 'select sysdate',
translated_text => 'SELECT SYSDATE FROM DUAL');
end;
/
--//注sql_text可以寫不對,但是前面一定開始是select,不然sqlplus無法識別是sql語句.
SCOTT@test01p> alter session set sql_translation_profile=test_profile;
Session altered.
SCOTT@test01p> alter session set events = '10601 trace name context forever, level 32';
Session altered.
D:\tools\rlwrap>oerr ora 10601
10601, 00000, "turn on debugging for cursor_sharing (literal replacement)"
// *Cause:
// *Action:
SCOTT@test01p> select sysdate;
SYSDATE
-------------------
2018-10-15 20:24:21
SCOTT@test01p> Select sysdate;
Select sysdate
*
ERROR at line 1:
ORA-00923: FROM keyword not found where expected
--//一定要與原來文字一樣.
--//重新整理共享池問題:
SCOTT@test01p> alter system flush shared_pool;
System altered.
SCOTT@test01p> select sysdate;
SYSDATE
-------------------
2018-10-15 20:27:07
SCOTT@test01p> SELECT INVALID SELECT STATEMENT TO FORCE ODBC DRIVER TO UNPREPARED STATE;
D
-
X
SYS@test> alter system flush shared_pool;
System altered.
SCOTT@test01p> select sysdate;
SYSDATE
-------------------
2018-10-15 20:27:50
--//我記憶裡早期12.1.0.1版本重新整理共享池後執行會報錯.12cR2版本修復這個錯誤.
3.看看記錄在那些表中,如何刪除等等操作.
--//涉及檢視:
DBA_ERROR_TRANSLATIONS
DBA_SQL_TRANSLATION_PROFILES
DBA_SQL_TRANSLATIONS
SCOTT@test01p> @ pt2 'select * from DBA_SQL_TRANSLATIONS where PROFILE_NAME=''TEST_PROFILE''';
ROW_NUM COL_NUM COL_NAME COL_VALUE
---------- ---------- -------------------- -------------------------------------------------------------
1 1 OWNER SCOTT
2 PROFILE_NAME TEST_PROFILE
3 SQL_TEXT select sysdate
4 TRANSLATED_TEXT SELECT SYSDATE FROM DUAL
5 SQL_ID bw2c1d6sqyjpy
6 HASH_VALUE 2976859838
7 ENABLED TRUE
8 REGISTRATION_TIME 2018-10-15 20:23:15.415000
8 rows selected.
SYS@test> @ sharepool/shp4 bw2c1d6sqyjpy 0
TEXT KGLHDADR KGLHDPAR C40 KGLHDLMD KGLHDPMD KGLHDIVC KGLOBHD0 KGLOBHD6 KGLOBHS0 KGLOBHS6 KGLOBT16 N0_6_16 N20 KGLNAHSH KGLOBT03 KGLOBT09
-------------- ---------------- ---------------- -------------- -------- ---------- ---------- ---------------- ---------------- ---------- ---------- ---------- --------- ---------- ---------- ------------- ----------
父遊標控制程式碼地址 000007FF130DCBC8 000007FF130DCBC8 select sysdate 1 0 0 00 00 0 0 0 0 0 2327677740 bw2c1d6sqyjpy 0
--//看到一個很奇怪的父遊標控制程式碼,沒有子游標,而且父遊標的堆0是0.
--//如果還有一些語句還可以加入:
BEGIN
dbms_sql_translator.register_sql_translation
(
profile_name => 'test_profile'
,sql_text => 'select user'
,translated_text => 'SELECT usera FROM DUAL'
);
END;
/
SCOTT@test01p> select user;
USER
--------------------
SCOTT
--//刪除執行如下:
SCOTT@test01p> exec dbms_sql_translator.drop_profile(profile_name => 'test_profile');
PL/SQL procedure successfully completed.
SCOTT@test01p> select sysdate;
select sysdate
*
ERROR at line 1:
ORA-00923: FROM keyword not found where expected
SCOTT@test01p> @ pt2 'select * from DBA_SQL_TRANSLATIONS where PROFILE_NAME=''TEST_PROFILE''';
no rows selected
4.順便看看這個包dbms_sql_translator的其它功能:
--//可以使用它計算sql_id:
SCOTT@test01p> select dbms_sql_translator.SQL_ID('select sysdate') c20 from dual ;
C20
--------------------
bw2c1d6sqyjpy
--//和前面的能對上.
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/267265/viewspace-2216487/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- [20210419]測試18c SQL Translation Framework.txtSQLFramework
- Translation – 起底 SourceKit
- Translation - 起底 SourceKit
- 12C SQL-TOPSQL
- IDEA外掛-TranslationIdea
- PHPSTORM外掛之TranslationPHPORM
- Oracle 12c 新SQL提示(hint)OracleSQL
- 12C SQL方面新特性小結SQL
- Translation unit v.s Compilation unit
- Manage SQL Plan Baselines in Oracle 12cSQLOracle
- PL/SQL Developer連線到Oracle 12cSQLDeveloperOracle
- 12c 使用SQL命令手工建立CDB數SQL
- SAP Spartacus Translation(翻譯) 相關話題
- Oracle 12c中的SQL/JSON函式OracleSQLJSON函式
- Oracle 12c中增強的PL/SQL功能OracleSQL
- #Paper Reading# Dual Learning for Machine TranslationMac
- Voltage Translation for Analog to Digital Interface ADCGit
- The Efficacy of Human Post-Editing for Language Translation(1)
- The Efficacy of Human Post-Editing for Language Translation(2)
- 好書推薦—《精通Oracle Database 12c SQL&PL/SQL程式設計》OracleDatabaseSQL程式設計
- Oracle 12c 檢視CDB&PDBs資訊(SQL*PLUS)OracleSQL
- CSS3中translate、transform、translation和animation的區別CSSS3ORM
- Manually Evolve and Accept SQL PLAN BASELINES in Oracle 12cSQLOracle
- Oracle GoldenGate 12c實時捕獲SQL Server資料OracleGoSQLServer
- 【論文筆記】Neural machine translation by jointly learning to align and translate筆記Mac
- 12C多租戶關於CDB、PDB的常用SQL語句SQL
- Oracle 12c 使用SQL*Plus來建立與移動應用程式SeedsOracleSQL
- Oracle 12c使用SQL*Plus來建立與刪除應用程式容器OracleSQL
- [20170620]11G 12c expand sql text.txtSQL
- oracle 12c 新特性三:rman命令視窗可以執行sql語句OracleSQL
- [20170726]11G 12c expand sql text 2.txtSQL
- 一條簡單的sql在11g和12c中的不同SQL
- [20131128]12c的dbms_utility.expand_sql_text.txtSQL
- 【12c Partitioning】Oracle 12c Partitioning特性Oracle
- Oracle 12cOracle
- [20230124]12c訪問login.sql指令碼.txtSQL指令碼
- [20130803]ORACLE 12C TOP N SQL實現分頁功能.txtOracleSQL
- Oracle 12C GDSOracle