[20180928]如何能在11g下執行.txt
[20180928]如何能在11g下執行.txt
--//連結問的問題: http://www.itpub.net/thread-2105467-1-1.html
create table test(t_id int,t_name varchar2(50));
create table test2(t_id int,t_name varchar2(50));
insert into test values(1,'a');
insert into test values(2,'b');
insert into test values(3,'c');
insert into test2 values(1,'a');
insert into test2 values(2,'b');
insert into test2 values(3,'c');
SELECT a.t_id, a.t_name
FROM test a
LEFT JOIN ( SELECT t_id, t_name
FROM test2
GROUP BY t_name) b
ON a.t_id = b.t_id AND a.t_name = b.t_name
WHERE a.t_id = 1
GROUP BY a.t_id, a.t_name;
--//同樣的sql ,在10g下就能執行,在11g下就會報錯 ora-00979 不是group by 表示式。紅色部分看起來確實是錯的,可是10g下整句
--//執行就有結果。如何能做到這個語句再11g下也能執行呢。
--//家裡沒有10g,使用12c測試看看,這條語句明顯錯誤( SELECT t_id, t_name FROM test2 GROUP BY t_name),這裡少寫了 GROUP BY
--//t_id,t_name.
1.環境:
SCOTT@test01p> @ ver1
PORT_STRING VERSION BANNER CON_ID
------------------------------ -------------- -------------------------------------------------------------------------------- ----------
IBMPC/WIN_NT64-9.1.0 12.1.0.1.0 Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production 0
2.測試:
SCOTT@test01p> select a.t_id,a.t_name from test a LEFT JOIN
2 (select t_id,t_name from test2 group by t_name) b
3 on a.t_id=b.t_id and a.t_name=b.t_name where a.t_id=1
4 group by a.t_id,a.t_name;
(select t_id,t_name from test2 group by t_name) b
*
ERROR at line 2:
ORA-00979: not a GROUP BY expression
--//12c 一樣報錯.
SCOTT@test01p> show parameter feature
NAME TYPE VALUE
------------------------------------ -------------------- ---------------
optimizer_adaptive_features boolean TRUE
optimizer_features_enable string 12.1.0.1
SCOTT@test01p> alter session set optimizer_features_enable='10.2.0.1';
Session altered.
SCOTT@test01p> SELECT a.t_id, a.t_name
2 FROM test a
3 LEFT JOIN ( SELECT t_id, t_name
4 FROM test2
5 GROUP BY t_name) b
6 ON a.t_id = b.t_id AND a.t_name = b.t_name
7 WHERE a.t_id = 1
8 GROUP BY a.t_id, a.t_name;
T_ID T_NAME
---------- --------------------------------------------------
1 a
--//OK透過.不過這句話明顯錯誤.看看執行計劃:
SCOTT@test01p> @ dpc '' advanced
PLAN_TABLE_OUTPUT
-------------------------------------
SQL_ID 0urvg3qakxxcx, child number 0
-------------------------------------
SELECT a.t_id, a.t_name FROM test a LEFT JOIN ( SELECT
t_id, t_name FROM test2
GROUP BY t_name) b ON a.t_id = b.t_id AND a.t_name =
b.t_name WHERE a.t_id = 1 GROUP BY a.t_id, a.t_name
Plan hash value: 1211648783
-----------------------------------------------------------------------------------------------------------
| Id | Operation | Name | E-Rows |E-Bytes| Cost (%CPU)| E-Time | OMem | 1Mem | Used-Mem |
-----------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | | | 9 (100)| | | | |
| 1 | HASH GROUP BY | | 1 | 40 | 9 (34)| 00:00:01 | 2063K| 2063K| 438K (0)|
| 2 | VIEW | | 1 | 40 | 8 (25)| 00:00:01 | | | |
| 3 | HASH GROUP BY | | 1 | 92 | 8 (25)| 00:00:01 | 1345K| 1345K| 486K (0)|
|* 4 | HASH JOIN OUTER | | 1 | 92 | 7 (15)| 00:00:01 | 1421K| 1421K| 722K (0)|
|* 5 | TABLE ACCESS FULL| TEST | 1 | 52 | 3 (0)| 00:00:01 | | | |
|* 6 | TABLE ACCESS FULL| TEST2 | 1 | 40 | 3 (0)| 00:00:01 | | | |
-----------------------------------------------------------------------------------------------------------
Query Block Name / Object Alias (identified by operation id):
-------------------------------------------------------------
1 - SEL$439AFB4F
2 - SEL$3DD9CB74 / $vm_view_0@SEL$439AFB4F
3 - SEL$3DD9CB74
5 - SEL$3DD9CB74 / A@SEL$3
6 - SEL$3DD9CB74 / TEST2@SEL$2
Outline Data
-------------
/*+
BEGIN_OUTLINE_DATA
IGNORE_OPTIM_EMBEDDED_HINTS
OPTIMIZER_FEATURES_ENABLE('10.2.0.1')
DB_VERSION('12.1.0.1')
ALL_ROWS
OUTLINE_LEAF(@"SEL$3DD9CB74")
MERGE(@"SEL$2")
OUTLINE_LEAF(@"SEL$439AFB4F")
OUTLINE(@"SEL$F2B2F603")
OUTLINE(@"SEL$2")
OUTLINE(@"SEL$CD8351FA")
MERGE(@"SEL$F1D6E378")
OUTLINE(@"SEL$4")
OUTLINE(@"SEL$F1D6E378")
MERGE(@"SEL$1")
OUTLINE(@"SEL$3")
OUTLINE(@"SEL$1")
NO_ACCESS(@"SEL$439AFB4F" "$vm_view_0"@"SEL$439AFB4F")
USE_HASH_AGGREGATION(@"SEL$439AFB4F")
FULL(@"SEL$3DD9CB74" "A"@"SEL$3")
FULL(@"SEL$3DD9CB74" "TEST2"@"SEL$2")
LEADING(@"SEL$3DD9CB74" "A"@"SEL$3" "TEST2"@"SEL$2")
USE_HASH(@"SEL$3DD9CB74" "TEST2"@"SEL$2")
USE_HASH_AGGREGATION(@"SEL$3DD9CB74")
END_OUTLINE_DATA
*/
Predicate Information (identified by operation id):
---------------------------------------------------
4 - access("A"."T_NAME"="T_NAME" AND "A"."T_ID"="T_ID")
5 - filter("A"."T_ID"=1)
6 - filter("T_ID"=1)
--//抽取outline.
--//編輯整理如下:
begin
dbms_sqltune.import_sql_profile(
name => 'profile_group_error',
description => 'SQL profile created manually test',
sql_text => q'[SELECT a.t_id, a.t_name
FROM test a
LEFT JOIN ( SELECT t_id, t_name
FROM test2
GROUP BY t_name) b
ON a.t_id = b.t_id AND a.t_name = b.t_name
WHERE a.t_id = 1
GROUP BY a.t_id, a.t_name]',
profile => sqlprof_attr(
'IGNORE_OPTIM_EMBEDDED_HINTS',
q'[OPTIMIZER_FEATURES_ENABLE('10.2.0.1')]',
q'[DB_VERSION('12.1.0.1')]',
'ALL_ROWS',
'OUTLINE_LEAF(@"SEL$3DD9CB74")',
'MERGE(@"SEL$2")',
'OUTLINE_LEAF(@"SEL$439AFB4F")',
'OUTLINE(@"SEL$F2B2F603")',
'OUTLINE(@"SEL$2")',
'OUTLINE(@"SEL$CD8351FA")',
'MERGE(@"SEL$F1D6E378")',
'OUTLINE(@"SEL$4")',
'OUTLINE(@"SEL$F1D6E378")',
'MERGE(@"SEL$1")',
'OUTLINE(@"SEL$3")',
'OUTLINE(@"SEL$1")',
'NO_ACCESS(@"SEL$439AFB4F" "$vm_view_0"@"SEL$439AFB4F")',
'USE_HASH_AGGREGATION(@"SEL$439AFB4F")',
'FULL(@"SEL$3DD9CB74" "A"@"SEL$3")',
'FULL(@"SEL$3DD9CB74" "TEST2"@"SEL$2")',
'LEADING(@"SEL$3DD9CB74" "A"@"SEL$3" "TEST2"@"SEL$2")',
'USE_HASH(@"SEL$3DD9CB74" "TEST2"@"SEL$2")',
'USE_HASH_AGGREGATION(@"SEL$3DD9CB74")'
),
replace => true,
force_match => TRUE
);
end;
/
SCOTT@test01p> show parameter feature
NAME TYPE VALUE
------------------------------------ -------------------- --------------
optimizer_adaptive_features boolean TRUE
optimizer_features_enable string 12.1.0.1
SCOTT@test01p> SELECT a.t_id, a.t_name
2 FROM test a
3 LEFT JOIN ( SELECT t_id, t_name
4 FROM test2
5 GROUP BY t_name) b
6 ON a.t_id = b.t_id AND a.t_name = b.t_name
7 WHERE a.t_id = 1
8 GROUP BY a.t_id, a.t_name;
T_ID T_NAME
---------- --------------------------------------------------
1 a
--//換1個數值,SELECT變成sELECT看看.
SCOTT@test01p> sELECT a.t_id, a.t_name
2 FROM test a
3 LEFT JOIN ( SELECT t_id, t_name
4 FROM test2
5 GROUP BY t_name) b
6 ON a.t_id = b.t_id AND a.t_name = b.t_name
7 WHERE a.t_id = 2
8 GROUP BY a.t_id, a.t_name;
T_ID T_NAME
---------- --------------------------------------------------
2 b
--//OK解決,最好還是叫開發改程式碼..
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/267265/viewspace-2215299/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- [20180928]exists與cardinality.txt
- [20180928]ora-01426(補充).txt
- [20180928]避免表示式在sql語句中.txtSQL
- [20190531]如何實現與執行.txt
- [20190416]11g下那些latch是Exclusive的.txt
- [20190415]11g下那些latch是共享的.txt
- [20221018]本地執行與遠端執行.txt
- [20190306]11g health monitor.txt
- [20190219]那個更快(11g).txt
- [20201130]11g or_expand提示.txt
- 如何在 Java 11 下執行 RocketMQJavaMQ
- [20230204]執行很慢的分析.txt
- Llama 3已能在iPhone或安卓手機上執行iPhone安卓
- [20211025]11g sequemce nocahe測試.txt
- [20201126]11g VPD的問題.txt
- [20190219]xargs -P實現並行執行.txt並行
- [20210926]並行執行計劃疑問.txt並行
- [20190111]執行計劃bitmap and.txt
- [20231012]奇怪的執行時長.txt
- [20230508]crack oracle執行檔案.txtOracle
- [20191104]禁止job以及SCHEDULER執行.txt
- [20191215]seq控制執行順序.txt
- [20190510]快速建立執行指令碼.txt指令碼
- [20230224]ssh date執行問題.txt
- 程式設計之路第17天:不能在ui執行緒執行阻塞操作,請使用setTimeout代替????程式設計UI執行緒
- 11G R2中的並行執行,dbms_parallel_execute並行Parallel
- [20201210]11G ACS相關問題.txt
- Java下如何保證多執行緒安全Java執行緒
- [20190111]執行計劃走位與.txt
- [20231021]生成bbed的執行指令碼.txt指令碼
- [20191112]flock控制命令執行順序.txt
- 透過DNS TXT記錄執行powershellDNS
- [20191220]格式化執行計劃.txt
- [20230130]toad看執行計劃注意.txt
- [20210418]開啟多個程式執行.txt
- [20191211]11g streams_pool_size引數.txt
- [20190214]11g Query Result Cache RC Latches.txt
- 如何在批處理模式下執行 top 命令模式