There is no βoptionβ in Oracle to do this; You can find a client who will allow you to do this, since this is a task that is usually performed in the client; I do not know one thing.
To expand tbone answer , you have to do it dynamically. This does not mean that you need to list each column. You would use a data dictionary , in particular all_tab_columns or user_tab_columns , to create a query. It would be easier to create a view with the exact definition that you want, so that you can reuse it if you want.
The goal is to take advantage of the fact that the existence of columns is stored in a table as a row to create a query to use that column. Because column names and table names are stored as strings, you can use row aggregation methods to easily create a query or DDL statement that you can execute manually or dynamically.
If you are using Oracle 11g Release 2, the listagg function is available to help you:
select 'create or replace view my_view as select ' || listagg( table_name || '.' || column_name || ' as ' || substr(table_name,1,1) || '_' || column_name, ', ') within group ( order by case when table_name = 'FOO' then 0 else 1 end , column_id ) || ' from foo f join bar b on f.id = b.foo_id' from user_tab_columns where table_name in ('FOO','BAR') ;
Assuming this table structure:
create table foo ( id number, a number, b number, c number); create table bar ( foo_id number, a number, b number, c number);
This single request creates the following:
create or replace view my_view as select FOO.ID as F_ID, FOO.A as F_A, FOO.B as F_B, FOO.C as F_C , BAR.FOO_ID as B_FOO_ID, BAR.A as B_A, BAR.B as B_B, BAR.C as B_C from foo f join bar b on f.id = b.foo_id
and here is the SQL Fiddle to prove it.
In that you are not using 11.2, you can achieve exactly the same results using the undocumented function wm_concat or the custom function stragg that was created by Tom Keith. Oracle Base has an article on row aggregation techniques , and there are many reports of stack overflows.
As a small addition, you can actually create what you are looking for with a slight modification to the above query. You can use the specified identifier to create a column in the format TABLE_NAME.COLUMN_NAME . You should quote it since . is not a valid character for an object name in Oracle. The advantage of this is that you get exactly what you want. The downside is that querying the created view is a huge pain if you don't use select * from ... ; selecting named columns will require quoting them.
select 'create or replace view my_view as select ' || listagg( table_name || '.' || column_name || ' as ' || '"' || table_name || '.' || column_name || '"', ', ') within group ( order by case when table_name = 'FOO' then 0 else 1 end , column_id ) || ' from foo f join bar b on f.id = b.foo_id' from user_tab_columns where table_name in ('FOO','BAR') ;
This query returns :
create or replace view my_view as select FOO.ID as "FOO.ID", FOO.A as "FOO.A", FOO.B as "FOO.B", FOO.C as "FOO.C" , BAR.FOO_ID as "BAR.FOO_ID", BAR.A as "BAR.A" , BAR.B as "BAR.B", BAR.C as "BAR.C" from foo f join bar b on f.id = b.foo_id