Many SQL databases support what the SQL standard calls a
. Such databases include at least CUBRID, Derby, Firebird, HSQLDB, Postgres, SQL
Since you MUST know the number of columns, but not necessarily the column names, you can use the WITH clause to rename these columns as you wish. For example (WITH works in Oracle and SQL Server, don't have MySQL instance handy):
WITH t(x,y,z) as (select * from TABLE(fn_returning_xcols(3)))
select * from t;
Here we don't know the column names in the inner select, but we can rename them in outer WITH clause.
Another example using a PIVOT in Oracle:
WITH t(a,b,c,d,e) as
(
select * from
(
select level as levl from dual connect by level <= 5
)
PIVOT(max(levl) as l for levl in (1,2,3,4,5))
)
select * from t;
Again, we don't care what the inner select column names are (the inner pivot creates somewhat odd column names), we just need to know how many columns and we can rename.