Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

can I use dynamic alias to name a column?

648346Jul 8 2008 — edited Jul 17 2008

I guys. I just want to know if it is possible to assign dynamic names to a column. for instance:

SQL> select sysdate+1 from dual;

SYSDATE+1
---------
09-JUL-08

the column name is SYSDATE+1. can I do something like:

SQL> select 1 as (select sysdate from dual) from dual;

(this throws error)

The reason for this requirement is that I need to assign a column name according to a value that comes from a parameter. So, instead of returning something like:

SQL> select sysdate, sysdate+1 from dual;

SYSDATE   SYSDATE+1
--------- ---------
08-JUL-08 09-JUL-08

I need to find a way to return something like:

SQL> select sysdate as <<dynamic column name based on parameter that has been passed in>>, sysdate+1 AS <<dynamic column name based on parameter that has been passed in>> from dual;

Obviously I can use something like:

select sysdate as "08-JUL-08", sysdate+1 AS "09-JUL-08" from dual;

But in this case I'm hard coding it. I need this alias to be dynamic.

Any way to do it?

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 13 2008
Added on Jul 8 2008
4 comments
12,877 views