[2016026]12c lateral語法.txt
[2016026]12c lateral語法.txt
12c 支援一種LATERAL的寫法,例子:
SELECT e1.*, e3.avg_sal
FROM scott.emp e1
,LATERAL (SELECT AVG (e2.sal) avg_sal
FROM scott.emp e2
WHERE e1.deptno != e2.deptno) e3;
-- 顯示emp每行,同時顯示其它不是本部門的平均薪水.我當時看到以上語句我想到如果不這樣寫,我個人並喜歡ansi的語法,
-- 但是像上面的語句,如果要寫以前11g下的語法,該如何寫呢?
-- 自己一下子也想不出來.看看10053跟蹤:
alter session set events '10053 trace name context forever, level 12';
SELECT e1.*, e3.avg_sal
FROM scott.emp e1
,LATERAL (SELECT AVG (e2.sal) avg_sal
FROM scott.emp e2
WHERE e1.deptno != e2.deptno) E3;
alter session set events '10053 trace name context off';
PLAN_TABLE_OUTPUT
-------------------------------------
SQL_ID 71hna731k6dk7, child number 0
-------------------------------------
SELECT e1.*, e3.avg_sal FROM scott.emp e1 ,LATERAL (SELECT AVG
(e2.sal) avg_sal FROM scott.emp e2
WHERE e1.deptno != e2.deptno) E3
Plan hash value: 4262987483
-----------------------------------------------------------------------------------------
| Id | Operation | Name | E-Rows |E-Bytes| Cost (%CPU)| E-Time |
-----------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | | | 45 (100)| |
| 1 | NESTED LOOPS | | 14 | 714 | 45 (0)| 00:00:01 |
| 2 | TABLE ACCESS FULL | EMP | 14 | 532 | 3 (0)| 00:00:01 |
| 3 | VIEW | VW_LAT_A18161FF | 1 | 13 | 3 (0)| 00:00:01 |
| 4 | SORT AGGREGATE | | 1 | 7 | | |
|* 5 | TABLE ACCESS FULL| EMP | 9 | 63 | 3 (0)| 00:00:01 |
-----------------------------------------------------------------------------------------
Query Block Name / Object Alias (identified by operation id):
-------------------------------------------------------------
1 - SEL$1
2 - SEL$1 / E1@SEL$1
3 - SEL$2 / E3@SEL$1
4 - SEL$2
5 - SEL$2 / E2@SEL$2
Predicate Information (identified by operation id):
---------------------------------------------------
5 - filter("E1"."DEPTNO"<>"E2"."DEPTNO")
--檢視10053跟蹤:
Final query after transformations:******* UNPARSED QUERY IS *******
SELECT "E1"."EMPNO" "EMPNO","E1"."ENAME" "ENAME","E1"."JOB" "JOB","E1"."MGR" "MGR","E1"."HIREDATE" "HIREDATE","E1"."SAL" "SAL","E1"."COMM"
"COMM","E1"."DEPTNO" "DEPTNO","VW_LAT_A18161FF"."AVG_SAL_0" "AVG_SAL"
FROM "SCOTT"."EMP" "E1", LATERAL( (
SELECT AVG("E2"."SAL") "AVG_SAL_0"
FROM "SCOTT"."EMP" "E2"
WHERE "E1"."DEPTNO" <> "E2"."DEPTNO")) "VW_LAT_A18161FF";
--看來這種語法不好轉換.我舉上面的例子實際上許多sql語句oracle最終轉換oracle為(+)的語法的.可以看看我以前的例子:
http://blog.itpub.net/267265/viewspace-1593068/
12c 支援一種LATERAL的寫法,例子:
SELECT e1.*, e3.avg_sal
FROM scott.emp e1
,LATERAL (SELECT AVG (e2.sal) avg_sal
FROM scott.emp e2
WHERE e1.deptno != e2.deptno) e3;
-- 顯示emp每行,同時顯示其它不是本部門的平均薪水.我當時看到以上語句我想到如果不這樣寫,我個人並喜歡ansi的語法,
-- 但是像上面的語句,如果要寫以前11g下的語法,該如何寫呢?
-- 自己一下子也想不出來.看看10053跟蹤:
alter session set events '10053 trace name context forever, level 12';
SELECT e1.*, e3.avg_sal
FROM scott.emp e1
,LATERAL (SELECT AVG (e2.sal) avg_sal
FROM scott.emp e2
WHERE e1.deptno != e2.deptno) E3;
alter session set events '10053 trace name context off';
PLAN_TABLE_OUTPUT
-------------------------------------
SQL_ID 71hna731k6dk7, child number 0
-------------------------------------
SELECT e1.*, e3.avg_sal FROM scott.emp e1 ,LATERAL (SELECT AVG
(e2.sal) avg_sal FROM scott.emp e2
WHERE e1.deptno != e2.deptno) E3
Plan hash value: 4262987483
-----------------------------------------------------------------------------------------
| Id | Operation | Name | E-Rows |E-Bytes| Cost (%CPU)| E-Time |
-----------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | | | 45 (100)| |
| 1 | NESTED LOOPS | | 14 | 714 | 45 (0)| 00:00:01 |
| 2 | TABLE ACCESS FULL | EMP | 14 | 532 | 3 (0)| 00:00:01 |
| 3 | VIEW | VW_LAT_A18161FF | 1 | 13 | 3 (0)| 00:00:01 |
| 4 | SORT AGGREGATE | | 1 | 7 | | |
|* 5 | TABLE ACCESS FULL| EMP | 9 | 63 | 3 (0)| 00:00:01 |
-----------------------------------------------------------------------------------------
Query Block Name / Object Alias (identified by operation id):
-------------------------------------------------------------
1 - SEL$1
2 - SEL$1 / E1@SEL$1
3 - SEL$2 / E3@SEL$1
4 - SEL$2
5 - SEL$2 / E2@SEL$2
Predicate Information (identified by operation id):
---------------------------------------------------
5 - filter("E1"."DEPTNO"<>"E2"."DEPTNO")
--檢視10053跟蹤:
Final query after transformations:******* UNPARSED QUERY IS *******
SELECT "E1"."EMPNO" "EMPNO","E1"."ENAME" "ENAME","E1"."JOB" "JOB","E1"."MGR" "MGR","E1"."HIREDATE" "HIREDATE","E1"."SAL" "SAL","E1"."COMM"
"COMM","E1"."DEPTNO" "DEPTNO","VW_LAT_A18161FF"."AVG_SAL_0" "AVG_SAL"
FROM "SCOTT"."EMP" "E1", LATERAL( (
SELECT AVG("E2"."SAL") "AVG_SAL_0"
FROM "SCOTT"."EMP" "E2"
WHERE "E1"."DEPTNO" <> "E2"."DEPTNO")) "VW_LAT_A18161FF";
--看來這種語法不好轉換.我舉上面的例子實際上許多sql語句oracle最終轉換oracle為(+)的語法的.可以看看我以前的例子:
http://blog.itpub.net/267265/viewspace-1593068/
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/267265/viewspace-1987029/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- lateral viewView
- 12C SQL Translation Framework.txtSQLFramework
- Hive-lateral view explodeHiveView
- [20160213]關於ansi語法.txt
- CMakeLists.txt 語法介紹與例項演練
- [20230905]奇怪的語法.txt
- [20160809]exp語法問題.txt
- [20180208]ezconnect語法.txt
- [20160803]exp/imp語法問題.txt
- hive中的 lateral view(側檢視)HiveView
- [20180912]關於ANSI joins語法.txt
- [20200227]使用tcpdump or and ()語法問題.txtTCP
- [20190624]12c group by優化 .txt優化
- [20160910]12c sqlldr express.txtSQLExpress
- [20170603]12c Top Frequency histogram.txtHistogram
- 英語語法
- [20190703]12c Hybrid histogram.txtHistogram
- JavaScript 新語法 「雙問號語法」與「可選鏈語法」JavaScript
- [20150724]無法通過sql_id找到sql語句.txtSQL
- sql case語法和plsql case語法!SQL
- [一、基本語法]1基本語法概述
- [20181005]安裝12C在windows.txtWindows
- [20131221]12c 優化 bug.txt優化
- [20130814]12c sqlplus.txtSQL
- 語法與語義
- Wfurent 語語法概述
- protobuf 語法,proto3 語法參考
- Dart語法篇之基礎語法(一)Dart
- JAVA語法糖和語法糖編譯Java編譯
- dockerfile 語法Docker
- markdown 語法
- 模板語法
- SQL語法SQL
- 語法糖
- Makedown語法
- JavaScript語法JavaScript
- Emmet語法
- jQuery 語法jQuery