Dynamic matrix SQL

Posted on 2006-06-08
Last Modified: 2010-10-05
Hi, I know the standard EMP matrix query via a decode, but I'd like a SQL that is dynamic with respect to the columns.
Using the EMP example, in my case I don't want to re-code the query once a new department is created.

We're on Oracle 9i. Isn't there a new [data warehousing] clause that allows me to do this?

Question by:shvanwijlen
    LVL 14

    Expert Comment

    As far as I know You need to write some PL/SQL code that will find distinct values (i.e. departments) from desired column and dynamically generate query for You.
    LVL 19

    Accepted Solution

    you could construct dynamic sql on the fly and "execute immediate" to return the result.

    here is the example:,F4950_P8_CRITERIA:15151874723724

    Author Comment

    This would work, but is there not a way to accomplish this via the "newer" functions such as rollup, cube, grouping sets?
    LVL 14

    Expert Comment

    I would say no because when You write select statement You need to know how many columns it will return - and this proves that there's no non-dynamic technique that will do the job for You (until You have some limitation on number of columns).
    LVL 19

    Expert Comment

    no such thing to specify dynamic columns in sql itself till now. You need to do it by yourself.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    PRTG Network Monitor: Intuitive Network Monitoring

    Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

    Suggested Solutions

    This article started out as an Experts-Exchange question, which then grew into a quick tip to go along with an IOUG presentation for the Collaborate confernce and then later grew again into a full blown article with expanded functionality and legacy…
    From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
    Video by: Steve
    Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
    This video shows how to Export data from an Oracle database using the Original Export Utility.  The corresponding Import utility, which works the same way is referenced, but not demonstrated.

    758 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now