2015-10-01 43 views
3

這可能是一個非常基本的問題,但我是Oracle的初學者。我運行一個簡單的查詢,它工作正常,並返回結果,但加入了*到顯示的列列表時,我收到以下錯誤:爲什麼添加*來查詢我得到一個錯誤?

ORA-00936: missing expression 
00936. 00000 - "missing expression" 
*Cause:  
*Action: 
Error at Line: 4 Column: 7 

我跑的查詢是:

select 
    sql_plan_hash_value col1 
    , elapsed_seconds col2 
    , * 
from 
    (select * 
    from SYS.V_$SESSION_LONGOPS 
    order by elapsed_seconds desc) result_set 
where rownum <= 10; 

我以爲這是因爲我沒有給我的前兩列別名,所以我做了,但查詢仍然無法正常工作。

回答

5

您不能將原始*與其他列混合。你需要使用適當的別名:

select 
    sql_plan_hash_value col1 
    , elapsed_seconds col2 
    , result_set.* --> Like this 
from 
    (select * 
    from SYS.V_$SESSION_LONGOPS 
    order by elapsed_seconds desc) result_set 
where rownum <= 10; 
+0

大聲笑,謝謝..從來沒有想過要添加結果集的別名。好奇爲什麼它需要'*',但不是前兩列。我會在10分鐘內接受你的答案。 –

相關問題