ORA-00979: not a GROUP BY expression報錯處理
環境:Oracle Database 11gR2(11.2.0.2) on Linux
故障現象: 執行Group By語句報錯ORA-00979。
具體的SQL如下:
SQL> select a.d1,a.EXIT_type,round(a.cnt1/b.cnt2*100,2) from
2 (select substr(LOGIN_DATE,1,8) d1,EXIT_type,count(*) cnt1 from xxx_connect_log group by substr(LOGIN_DATE,1,8),EXIT_type) a,
3 (select substr(LOGIN_DATE,1,8) d2 ,count(*) cnt2 from xxx_connect_log group by substr(LOGIN_DATE,1,8) ) b
4 where A.d1=B.d2 order by a.d1,a.EXIT_type;
(select substr(LOGIN_DATE,1,8) d2 ,count(*) cnt2 from xxx_connect_log group by substr(LOGIN_DATE,1,8) ) b
*
ERROR at line 3:
ORA-00979: not a GROUP BY expression
4 where A.d1=B.d2 order by a.d1,a.EXIT_type;
(select substr(LOGIN_DATE,1,8) d2 ,count(*) cnt2 from xxx_connect_log group by substr(LOGIN_DATE,1,8) ) b
*
ERROR at line 3:
ORA-00979: not a GROUP BY expression
這條語句在其他大區的DB上執行均OK,在體驗服DB上執行報錯。從語法上看,確實是完全沒問題的。
碰到這種ORA-報錯的情況,我們可以透過設定ErrorStack對錯誤堆疊進行跟蹤,將錯誤的後臺資訊比較詳盡的轉儲到跟蹤檔案,供分析研究。
ErrorStack的四個級別及說明:
0 Error stack only
1 Error stack and function call stack
2 As level 1 plus the process state
3 As level 2 plus the context area
ErrorStack僅在特定的錯誤出現的時候才被觸發。可以在例項或者會話級別進行設定。
下面我們進行979的ErrorStack跟蹤:
SQL> alter system set events='979 trace name errorstack forever,level 3';System altered.
SQL> select a.d1,a.EXIT_type,round(a.cnt1/b.cnt2*100,2) from
2 (select substr(LOGIN_DATE,1,8) d1,EXIT_type,count(*) cnt1 from xxx_connect_log group by substr(LOGIN_DATE,1,8),EXIT_type) a,
3 (select substr(LOGIN_DATE,1,8) d2 ,count(*) cnt2 from xxx_connect_log group by substr(LOGIN_DATE,1,8) ) b
4 where A.d1=B.d2 order by a.d1,a.EXIT_type;
(select substr(LOGIN_DATE,1,8) d2 ,count(*) cnt2 from xxx_connect_log group by substr(LOGIN_DATE,1,8) ) b
*
ERROR at line 3:
ORA-00979: not a GROUP BY expression
SQL> alter system set events='979 trace name errorstack off';
System altered.
System altered.
alert日誌中的內容:
Fri May 31 13:19:20 2013
OS Pid: 29652 executed alter system set events '979 trace name errorstack forever,level 3'
Errors in file /u/ora11g/diag/rdbms/xxxtest/xxxtest/trace/xxxtest_ora_29652.trc:
ORA-00979: not a GROUP BY expression
Fri May 31 13:19:27 2013
Dumping diagnostic data in directory=[cdmp_20130531131927], requested by (instance=1, sid=29652), summary=[abnormal process termination].
Fri May 31 13:19:52 2013
OS Pid: 29652 executed alter system set events '979 trace name errorstack off'
對應的跟蹤檔案是: /u/ora11g/diag/rdbms/xxxtest/xxxtest/trace/xxxtest_ora_29652.trc
我們來檢視跟蹤檔案中具體的資訊:
dbkedDefDump(): Starting a non-incident diagnostic dump (flags=0x0, level=12, mask=0x0)
----- Error Stack Dump -----
ORA-00979: not a GROUP BY expression
----- Current SQL Statement for this session (sql_id=d2ccw741whuh0) -----
select a.d1,a.EXIT_type,round(a.cnt1/b.cnt2*:"SYS_B_0",:"SYS_B_1") from
(select substr(LOGIN_DATE,:"SYS_B_2",:"SYS_B_3") d1,EXIT_type,count(*) cnt1 from xxx_connect_log group by substr(LOGIN_DATE,:"SYS_B_4
",:"SYS_B_5"),EXIT_type) a,
(select substr(LOGIN_DATE,:"SYS_B_6",:"SYS_B_7") d2 ,count(*) cnt2 from xxx_connect_log group by substr(LOGIN_DATE,:"SYS_B_8",:"SYS_B
_9") ) b
where A.d1=B.d2 order by a.d1,a.EXIT_type
----- Call Stack Trace -----
calling call entry argument values in hex
location type point (? means dubious value)
-------------------- -------- -------------------- ----------------------------
skdstdst()+36 call kgdsdst() 000000000 ? 000000000 ?
7FFFA7A0B468 ? 000000001 ?
000000001 ?
...
在跟蹤檔案中,我們看到針對我們發出的SQL,在Oracle底層已經將一些資料替換成了繫結變數,這個是因為我們設定了cursor_sharing=FORCE的。
那麼對於這個SQL,是否是因為cursor_sharing這個設定導致group by報錯了呢?
查詢了metalink,Cursor_sharing確實有對應的Bug會導致這個報錯:
8913729 | 11.2.0.2, 12.1.0.0 | ORA-979 with CURSOR_SHARING=SIMILAR or FORCE |
文件上宣稱是11.2.0.2中是修復了此Bug的。但我們的環境就是11.2.0.2的哦。搞毛?
透過Oracle的堆疊資訊確認了是bug 8913729。
類似的堆疊資訊如下:
kgesev
解決方法:
以下幾種都可以解決:
1:透過設定CURSOR_SHARING=EXACT;
2:在SQL語句中使用hint /*+ CURSOR_SHARING_EXACT */;
3:設定optimizer_features_enable引數為10.2.0.5或者11.1.0.7(現在的值是11.2.0.2)。
我們選擇第2種方式來解決:
修改後的SQL如下:
select /*+ CURSOR_SHARING_EXACT */ a.d1,a.EXIT_type,round(a.cnt1/b.cnt2*100,2) from
(select substr(LOGIN_DATE,1,8) d1,EXIT_type,count(*) cnt1 from xxx_connect_log group by substr(LOGIN_DATE,1,8),EXIT_type) a,
(select substr(LOGIN_DATE,1,8) d2 ,count(*) cnt2 from xxx_connect_log group by substr(LOGIN_DATE,1,8) ) b
where A.d1=B.d2 order by a.d1,a.EXIT_type;
已證實可行。
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29154652/viewspace-772504/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- [Developer] ORA-00979:not a group by expressionDeveloperExpress
- mysql報錯:Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggreMySqlExpressAI
- Extjs報錯處理JS
- DG報錯的處理
- errpt報錯處理
- Gulp壓縮報錯處理
- rails gem報錯的處理AI
- Javascript程式碼報錯處理JavaScript
- 各種報錯處理方法
- Too many open files報錯處理
- Mysql自動處理同步報錯MySql
- yum groupinstall報錯,處理方法
- ORA-02429 報錯處理
- mysql複製報錯案例處理MySql
- Python 入門級報錯處理Python
- 批處理的聊天程式報錯求救!!!!!
- Android switch語句報錯Constant expression requiredAndroidExpressUI
- object dict cannot be used in await expression報錯解釋ObjectAIExpress
- 線上MYSQL同步報錯故障處理總結MySql
- ORA-1654報錯處理一則
- 匯入專案@override 報錯處理IDE
- EBS服務啟動報錯基本處理
- pl/sql developer除錯儲存過程報錯處理SQLDeveloper除錯儲存過程
- 解決報錯error the @annotation pointcut expression is only supported at Java 5ErrorExpressJava
- Mysql報錯注入原理分析(count()、rand()、group by)MySql
- Oracle 12c ORA-29548 報錯處理Oracle
- 線上MYSQL同步報錯故障處理方法總結MySql
- ADG--Ora-30927報錯處理
- 【故障處理】 DBCA建庫報錯CRS-2566
- COM+元件啟動報錯問題處理元件
- 錯誤處理
- Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggreExpressAI
- ora-04045和ora-16000報錯處理
- Fatal NI connect error 12170.報錯處理Error
- CI中RESTURL含有中文怎麼處理(報錯:TheURIyousubmittedhasdisallowedcharacters)RESTMIT
- 一次歸檔報錯的處理和分析
- RAC環境TNS-12541報錯處理
- 處理動態連結庫報錯的問題