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!

Dynamic Column Headers

525708Oct 13 2010 — edited Oct 13 2010
Dear Members,

I have a sql as below:
select msi.segment1,
        sum(CASE WHEN mdh.period_start_date > trunc(add_months(sysdate,-1))
                       THEN mdh.sales_order_demand ELSE 0 END) MONTH_USAGE_1
from mtl_demand_histories mdh,
     mtl_system_items msi
where msi.inventory_item_id = mdh.inventory_item_id and
      msi.organization_id = mdh.organization_id
group by segment1
From the above sql the 2nd column name(MONTH_USAGE_1) should be dynamic and the name can be derived from the following:

to_char(trunc(add_months(sysdate,-1)),'MON-RRRR') which will result in SEP-2010.

So the 2nd column name should be SEP-2010.

How can i do this in SQL.

Thanks
Sandeep
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 10 2010
Added on Oct 13 2010
3 comments
1,961 views