PL/SQL (MOSC)

MOSC Banner

Discussions

Why I get ORA-00904 when I use "select * union all order by <column_name>?

edited Jun 16, 2014 1:38AM in PL/SQL (MOSC) 10 commentsAnswered ✓

Oracle: 11.2.0.4  AIX: 6.1

Please can you explain me, why I get

   ORA-00904: "F1": invalid identifier

when I do following select:

select * from t1

union all

select * from t1_copy

order by f1;

When I use a number in "order by" then the query runs fine:

select * from t1

union all

select * from t1_copy

order by 1;

The query also runs fine when I use a column_list instead of "*":

select f1 from t1

union all

select f1 from t1_copy

order by f1;

Here a small test case:

create table t1 (f1 number);

create table t1_copy (f1 number);

insert into t1 values (1);

Howdy, Stranger!

Log In

To view full details, sign in to My Oracle Support Community.

Register

Don't have a My Oracle Support Community account? Click here to get started.

New to My Oracle Support Community? Visit our Welcome Center

MOSC Help Center