it's possible to alias all column with a prefix, in a select? I have a group of tables in an Oracle db that I need to join together, and most of them have the same column names. I would like to have something like
select MAGIC_ADD_PREFIX("PREFIX", *) from TABLE
and have a result like
+---------+----------+----------+
|PREFIX_ID|PREFIX_FOO|PREFIX_BAR|
+---------+----------+----------+
|... | | |
ATM the only thing I can think is something chumsky like
select ID PREFIX_ID, FOO PREFIX_FOO, BAR PREFIX_BAR from TABLE
but it's ugly as hell and error-prone
==== further explanation ====
The problem with
select TABLE.*,...
is that I'm using java + jdbc drivers to retrieve the columns, and the java.sql.ResultSet
methods (resultset.getInt("COLUMNNAME")
, .getString("COLUMNNAME")
...) doesn't support the syntax "TABLENAME.COLUMNAME".
if I do (simplified, no error cheks...)
ResultSet rs = mkResultSet("select * from table_a, table_b");
rs.next();
System.out.println(rs.getInt("table_a.id"));
I get a SQLException
with invalid column name as message