为什么在向查询添加*时出现错误?

Rad*_*hiu 3 oracle plsql

这可能是一个非常基本的问题,但我是Oracle的初学者.我正在运行一个简单的查询,它可以正常工作并返回结果,但是当向*显示的列列表中添加一个时,我得到以下错误:

ORA-00936: missing expression
00936. 00000 -  "missing expression"
*Cause:    
*Action:
Error at Line: 4 Column: 7
Run Code Online (Sandbox Code Playgroud)

我正在运行的查询是:

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;
Run Code Online (Sandbox Code Playgroud)

我认为这是因为我没有给前两列的别名,所以我做了,但查询仍然无效.

Álv*_*lez 5

您不能将raw *与其他列混合使用.您需要使用适当的别名:

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;
Run Code Online (Sandbox Code Playgroud)