Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why when adding * to query I get an error?

This is probably a very very basic issue but I'm a beginner with Oracle. I'm running a simple query, which works fine and returns results, but when adding a * to the list of columns displayed, I get the below error:

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

The query I'm running is:

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;

I thought that it's because I'm not giving aliases to my first two columns, so I did, but the query is still not working.

like image 927
Radu Gheorghiu Avatar asked Dec 13 '25 02:12

Radu Gheorghiu


1 Answers

You can't mix raw * with other columns. You need to use the appropriate alias:

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;
like image 59
Álvaro González Avatar answered Dec 14 '25 18:12

Álvaro González



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!