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!

Pivot / Vertical table

Olav Alexander MjeldeAug 18 2010 — edited Aug 18 2010
Hi,

I wish to have a vertical output of a query.

The query looks like so (only MANY more columns and tables):
SELECT  (
        SELECT  count(*)
        FROM  db.aks@"dblink"
        ) as aks,
        (
        SELECT count(*)  
        FROM   db.arkenh@"dblink"
        ) as arkenh
FROM    dual   
It is quite simple, a count(*) on rows in many tables.

The output at the moment is horizontal, eg:
aks | arkenh | foo | bar | etc |
992| 92932 | 928 | 23 | 929 |
How ever, I wish to "flip" it, I believe it's called a pivot table(?).
I have looked at both making a new outer query, using the IN.

I have also tried using the pivot function, but It didnt work very well.
The outer query just gave the same horizontal results.

This is how I want it:
Data | Number | Description
aks   | 992       | This data ...
ark.. | 92932   | bla bla bla
I can mange to flip it in the reports that Apex has, with some other templates.. But when exporting to excel, it reverts to the horizontal view.

atm. I have approx 20-40 tables in one query.. It was yesterday 136 tables, but I cleaned it up and removed the ones that we were not using.

btw. using linked databases, both oracle.
I can not write in the source DB (read only user), but I can write in the one that runs the query.
As for the description, it is not stored in the db.. But I thought I could just select a string as Description.

(it's a static help text for the database column name).
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 15 2010
Added on Aug 18 2010
2 comments
1,464 views