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!

Joining a table with all_tab_columns

797021Aug 7 2013 — edited Aug 7 2013

How is it possible to join a table with the tab_columns?

The query im trying to establish is that in my table they are 12 columns with months names. So under an input variable im trying to return the required values with the selected months. The only way i could think of to get the months to connect with the tab_columns table.

Any suggestion is really appreciated

SELECT bust,

Sum(jan) JAN,

Sum(feb) FEB,

Sum(mar) MAR,

Sum(apr) APR,

Sum(may) MAY,

Sum(jun) JUN,

Sum(jul) JUL,

Sum(aug) AUG,

Sum(sep) SEP,

Sum(oct) OCT,

Sum(nov) NOV,

Sum(DEC) DECC

FROM budget a,all_tab_columns b

WHERE vsl_code = 4602

AND code = 1

AND year=2013

AND account_code='30'

AND b.table_name='BUDGET'

AND b.column_name IN

                     (SELECT column_name

                      FROM (SELECT Column_name, ROWNUM r

                                    FROM all_tab_columns b

                                    WHERE table_name = 'BUDGET'

                                    AND Column_id BETWEEN 3 AND 14

                                    ORDER BY column_id)

                      WHERE r BETWEEN 2 AND 3 ) --Returns February,March

group by bust;

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 4 2013
Added on Aug 7 2013
2 comments
1,196 views