[20170620]11G 12c expand sql text.txt
[20170620]11G 12c expand sql text.txt
--//原來寫的指令碼只能分別在11g,12c單獨使用.上午花一點點時間.把兩者整合起來.
--//討論連結:http://www.itpub.net/thread-2088981-1-1.html
--//再次感謝solomon_007的指點:
set long 20000
set serveroutput on
declare
L_sqltext clob := null;
l_version varchar2(3) := null;
l_sql clob := null;
l_result clob := null;
begin
select regexp_replace(version,'\..*') into l_version from v$instance;
select sql_fulltext into l_sqltext from v$sqlarea where sql_id='&&1';
if l_version = '11' then
l_sql := 'begin
dbms_sql2.expand_sql_text( :a,:b );
end;';
elsif l_version = '12' then
l_sql := 'begin
dbms_utility.expand_sql_text(:a,:b);
end;';
end if;
execute immediate l_sql using in l_sqltext,out l_result;
dbms_output.put_line(l_result);
end;
/
set serveroutput off
--//繼續拿原來的例子測試:
SCOTT@book> @ &r/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
create table t1( id, col1, col2, col3, col4, col5, padding )
cache
pctfree 95 pctused 5
-- compress for query low
as
select
1, 100 , 200 , 300 , 400 , 500,rpad('x',100)
from
all_objects
where
rownum <= 50000 ;
execute dbms_stats.gather_table_stats(user,'t1',method_opt=>'for all columns size 1')
select
/*+ gather_plan_statistics find this */
id, max(val) as high_val
from
t1
unpivot include nulls (
val for source in (col1, col2, col3, col4, col5)
)
group by id
order by id
;
--//獲得sql_id=2v7uzcnf4kj9s.
SCOTT@book> @ &r/expand_sql_text 2v7uzcnf4kj9s
SELECT "A1"."ID" "ID",MAX("A1"."VAL") "HIGH_VAL" FROM ( (SELECT "A3"."ID" "ID","A3"."PADDING" "PADDING",'COL1' "SOURCE","A3"."COL1" "VAL" FROM "SCOTT"."T1" "A3") UNION ALL (SELECT "A4"."ID" "ID","A4"."PADDING" "PADDING",'COL2' "SOURCE","A4"."COL2"
"VAL" FROM "SCOTT"."T1" "A4") UNION ALL (SELECT "A5"."ID" "ID","A5"."PADDING" "PADDING",'COL3' "SOURCE","A5"."COL3" "VAL" FROM "SCOTT"."T1" "A5") UNION ALL (SELECT "A6"."ID" "ID","A6"."PADDING" "PADDING",'COL4' "SOURCE","A6"."COL4" "VAL" FROM
"SCOTT"."T1" "A6") UNION ALL (SELECT "A7"."ID" "ID","A7"."PADDING" "PADDING",'COL5' "SOURCE","A7"."COL5" "VAL" FROM "SCOTT"."T1" "A7")) "A1" GROUP BY "A1"."ID" ORDER BY "A1"."ID"
PL/SQL procedure successfully completed.
--//toad格式化看看:
/* Formatted on 2017/6/20 16:10:46 (QP5 v5.269.14213.34769) */
SELECT "A1"."ID" "ID", MAX ("A1"."VAL") "HIGH_VAL"
FROM ( (SELECT "A3"."ID" "ID"
,"A3"."PADDING" "PADDING"
,'COL1' "SOURCE"
,"A3"."COL1" "VAL"
FROM "SCOTT"."T1" "A3")
UNION ALL
(SELECT "A4"."ID" "ID"
,"A4"."PADDING" "PADDING"
,'COL2' "SOURCE"
,"A4"."COL2" "VAL"
FROM "SCOTT"."T1" "A4")
UNION ALL
(SELECT "A5"."ID" "ID"
,"A5"."PADDING" "PADDING"
,'COL3' "SOURCE"
,"A5"."COL3" "VAL"
FROM "SCOTT"."T1" "A5")
UNION ALL
(SELECT "A6"."ID" "ID"
,"A6"."PADDING" "PADDING"
,'COL4' "SOURCE"
,"A6"."COL4" "VAL"
FROM "SCOTT"."T1" "A6")
UNION ALL
(SELECT "A7"."ID" "ID"
,"A7"."PADDING" "PADDING"
,'COL5' "SOURCE"
,"A7"."COL5" "VAL"
FROM "SCOTT"."T1" "A7")) "A1"
GROUP BY "A1"."ID"
ORDER BY "A1"."ID";
--//可以看出使用unpivot實際上內部要全表掃描T1 5次.
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/267265/viewspace-2141010/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- [20170619]11G expand sql text.txtSQL
- [20211123]完善expand sql text.txtSQL
- [20170726]11G 12c expand sql text 2.txtSQL
- [20131128]12c的dbms_utility.expand_sql_text.txtSQL
- 一條簡單的sql在11g和12c中的不同SQL
- oracle 12c 匯入11gOracle
- 12C SQL-TOPSQL
- oracle hint_no_expand_no_factOracle
- Oracle 11g升級到12COracle
- plsql的命令(command)視窗與sql視窗有什麼區別20170620SQL
- 12C SQL Translation Framework.txtSQLFramework
- Oracle 12c 新SQL提示(hint)OracleSQL
- vimscript-expand函式詳解函式
- 12C SQL方面新特性小結SQL
- WebLogic Server 11g and 12c Configure SSLWebServer
- Oracle 11g系列:SQL Plus與PL/SQLOracleSQL
- expand 與 unexpand 命令例項教程
- Manage SQL Plan Baselines in Oracle 12cSQLOracle
- PL/SQL Developer連線到Oracle 12cSQLDeveloperOracle
- 12c 使用SQL命令手工建立CDB數SQL
- 11g v$sql 新增列SQL
- 11G new SQL hint大全SQL
- Oracle 11g/12c 監聽器白名單的配置Oracle
- 角色resource在11g和12c中的區別
- Oracle 12c中的SQL/JSON函式OracleSQLJSON函式
- Oracle 12c中增強的PL/SQL功能OracleSQL
- Oracle 11g,12c,18c,19,21,23 RUOracle
- A taste of SQL Performance Analyzer in oracle 11gASTSQLORMOracle
- Oracle 11g SQL效能的新特性(三)- SQL Plan ManagementOracleSQL
- 【SQL Performance Analyzer】Oracle 11g SQL Performance Analyzer feature使用SQLORMOracle
- 好書推薦—《精通Oracle Database 12c SQL&PL/SQL程式設計》OracleDatabaseSQL程式設計
- Oracle 12c 檢視CDB&PDBs資訊(SQL*PLUS)OracleSQL
- 11g文件學習----sql連線SQL
- oracle 11g監控SQL指令碼OracleSQL指令碼
- Linux基礎命令—格式轉換expand、unexpandLinux
- 10g/11g/12c RMAN學習(final) - show all 4
- Oracle 隱藏引數(9i,10g,11g,12c)Oracle
- Oracle 11g 新特性 -- SQL Plan Management 示例OracleSQL