11g PIVOT uses static columns - why why why???

I am very curios to know why we have to hard-code the "pivot in" clause in a pivot query. Does this not defeat the purpose of pivoting?
we have to write this:
SELECT *
FROM (SELECT customer_id, product_code, quantity
FROM pivot_test)
PIVOT (SUM(quantity) AS sum_quantity FOR (product_code) IN ('A' AS a, 'B' AS b, 'C' AS c))
ORDER BY customer_id;
Why can we not put a subquery in the "IN" clause? Or even better, leave it blank to indicate we are pivoting for all.
I know you can do something like this with the PIVOT XML function, but I want columns in the result, not XML. And I also do not want to build the query as a string and execute it like that, it gets really messy and I feel sorry for the next bloke who needs to take over from me.
Does anybody know why this seems to not be possible for ORACLE?
Thanks all.

In addition to the excellent relational theory reasons the SQL standard (and relational database vendors) can't do dynamic pivots, there are important practical problems.
Every API that interacts with any database (ODBC, JDBC, ODP.Net, ADO, DAO, OLE DB, OO4O, etc.) goes through a series of steps in order to execute a SQL statement.
1) The statement is prepared.
2) The bind variables are bound and return variables are created
3) The statement is executed.
Preparing the statement involves the database parsing the query (but not executing it). This provides the client with a statement handle that can be interrogated to, for example, describe the result set to expect. This allows the client to determine that, for example, a query is going to return 5 columns, the first of which is an integer and the next 4 of which are VARCHAR2(100)'s. The client then knows what data structures it needs to allocate. Since this statement handle is potentially going to be cached and reused many times with many different sets of bind variables, the structure of the result needs to be fixed.
If a database permitted the structure of the query to change because data changed, it would cause massive havoc across every application that interacted with the database. You'd have to add something to every database API that allowed the database to come back from an attempt to execute a query and say "hey, I know I told you a while ago that this query was going to return 5 columns-- turns out, now it returns 6 (or 4 or 17)". Tons of code that relies on these APIs would need to be rewritten to be able to handle that exception, discard the cached handles, reallocate the data structures, re-execute the query, and figure out what, if any, downstream impacts that has on the application code. That would be a massive undertaking and would create much more work than would be saved by allowing a dynamic pivot.
Justin

Similar Messages

  • Why not to use static methods - with example

    Hi Everyone,
    I'd like to continue the below thread about "why not to use static methods"
    Why not to use static methods
    with a concrete example.
    In my small application I need to be able to send keystrokes. (java.awt.Robot class is used for this)
    I created the following class for these "operations" with static methods:
    public class KeyboardInput {
         private static Robot r;
         static {
              try {
                   r = new Robot();
              } catch (AWTException e) {
                   throw new RuntimeException(e + "Robot couldn't be initialized.");
         public static void wait(int millis){
              r.delay(millis);
         public static void copy() {
              r.keyPress(KeyEvent.VK_CONTROL);
              r.keyPress(KeyEvent.VK_C);
              r.keyRelease(KeyEvent.VK_C);
              r.keyRelease(KeyEvent.VK_CONTROL);
         public static void altTab() {
              r.keyPress(KeyEvent.VK_ALT);
              r.keyPress(KeyEvent.VK_TAB);
              r.keyRelease(KeyEvent.VK_TAB);
              r.keyRelease(KeyEvent.VK_ALT);
                   // more methods like  paste(), tab(), shiftTab(), rightArrow()
    }Do you thinks it is a good solution? How could it be improved? I've seen something about Singleton vs. static methods somewhere. Would it be better to use Singleton?
    Thanks for any comments in advance,
    lemonboston

    maheshguruswamy wrote:
    lemonboston wrote:
    maheshguruswamy wrote:
    I think a singleton might be a better approach for you. Just kill the public constructor and provide a getInstance method to provide lazy initialization.Thanks maheshguruswamy for advising on the steps to create a singleton from this class.
    Could you maybe advise also about why do you say that it would be better to use singleton? What's behind it? Thanks!In short, it seems to me that a single instance of your class will be able to coordinate actions across your entire application. So a singleton should be enough.But that doesn't answer why he should prefer a singleton instead over a bunch of static methods. Functionally the two are almost identical. In both cases there's only one "thing" on which to call methods--either a single instance of the class, or the class itself.
    To answer the question, the main reason to use a Singleton over a classful of static methods is the same reason the drives a lot of non-static vs. static decisions: Polymorphism.
    If you use a Singleton (and and interface), you can do something like this:
    KeyboardInput kbi = get_some_instance_of_some_class_that_implements_KeyboardInput_somehow_maybe_from_a_factory();And then whatever is calling KBI's public methods only has to know that it has an implementor of that interface, without caring which concrete class it is, and you can substitute whatever implementation is appropriate in a given context. If you don't need to do that, then the static method approach is probably sufficient.
    There are other reasons that may suggest a Singleton--serialization, persistence, use as a JavaBean pop to mind--but they're less common and less compelling in my experience.
    And finally, if this thing maintains any state between method calls, although you can handle that with static member variables, it's more in keeping with the OO paradigm to make them non-static fields of an instance of that class.

  • Why can't I use the Column Browser for my iPod when connected to the computer?

    In iTunes 11, I can use the Column Browser while viewing my music library on the computer.  But it's inexplicably not available for viewing the music on my iPod when it's connected to the computer to sync.
    The Column Browser is the simplest, easiest, most elegant way for me to review what's on my iPod, and create Playlists from my music and CD books.  It was available in 10.7 and is available on the computer, why not the iPod????!!!???
    Why mess around changing something that isn't broken - after all these years why can't that option still be available?  It doesn't have to be the default, just be available. Will I have to downgrade to 10.7 yet again????
    And you don't even have a relevant category for me to choose from below!!  It makes sense to me that you provide a general "Using iTunes" category.

    Thanks for your reply, but I've already done that and the Column Browser options are completely grayed out.  I've taken a screen shot and hope I can paste it in here.  You'll see I have the sidebar open.  That's the way I prefer to deal with iTunes.
    This happened after I updated to iTunes 11.0.4.  Perhaps that changed the setting options. I think I had the Column Browser option prior to that, but I just got a new iPod and I was busy loading stuff, so not completely sure if it worked before the update.  But I think I would have noticed, because it bugs me so much not to have the option.

  • Why do we use static block ????

    my question is that why do we use static block for certain statements and declarations ?? what advantage do they hold???
    Please help me........

    Here is an example:
    If you use a JDBC-driver, it's enough to write:
       String driverName = "package.MyDriver";
       Class.forName(driverName);In the class "MyDriver" there is a static block:
    public class MyDriver implements java.sql.Driver {
       static {
          MyDriver driver = new MyDriver();
          java.sql.DriverManager.registerDriver(driver);
    }

  • When I try to use 'Stacked Column Bar'. with data assigned in the graphs, and want to see it in the 'Preview' mode in Xeclsius, I unable to see the graphs apart from the Axes ans Series Value, the graphs becomes totaly invisible why So ?

    When I try to use 'Stacked Column Bar'. with data assigned in the graphs, and want to see it in the 'Preview' mode in Xeclsius, I unable to see the graphs apart from the Axes ans Series Value, the graphs becomes totally invisible why So ?

    Hi Ranendra,
    For basic understanding of Dashboards and Models you can use standard Templates or samples which ll come along with dashboard designer(Formly Xcelsius) installation.
    For path   File-->Templates(or Samples).
    Under Templates you ll have different categories and for each you ll find the dashboard Templates.
    Regards,
    Venkat P

  • The column browser is no longer available when trying to view music in iTunes. I'm only able to use the column browser only when viewing playlists. Why?

    I noticed that after one of the recent updates to iTunes, I am unable to view my music using the column browser type view. Only when I select one of my playlists is the music displayed with the column browser. When I select Music to view the contents of my library, only the album covers are displayed on the right side. The old column browser type display is not available any more - it is grayed out. I do have "show list views for all media" checked in my Preferences / General tab.
    Did Apple screw up or is it me?

    You're welcome.
    tt2

  • Why can't I use static IP anymore?

    I just set up a new intel Mini as part of my media center. I want to do like the other Macs on my network -- use static IP addresses and port forwarding to allow vnc connections.
    I'm connected via ethernet. I get dhcp just fine. But when I take the dhcp address, or, for that matter, the next static IP in line, I lose all connectivity to the internet. I've verified that my dns settings are correct.
    This is driving me crazy. For example, 192.168.1.106 is what it grabs from dhcp, and it works just fine. If I switch to manual and set if for the exact same thing, it goes offline and won't come back until I switch it back to dhcp.
    Any ideas? I've got an XP box and two G5's (Tiger) all configured with staticIP/port forwarding, and they work just fine.
    Thanks.

    Don't forget that there are many "pieces" to internet access that must all be set to make manual IP selection work, namely:
    1) Your IP address
    2) The addresses of your DNS servers
    3) The default route via which packets leave your network ("router" in Network->TCP/IP)
    4) Your subnet mask
    As mentioned above you also need to assign an address from outside the DHCP pool that is on the same subnet, as at least some routers will refuse to route traffic that seems to originate from IP addresses that fall within the DHCP pool over which it has control if it did not yet assign that IP address to a client.

  • I can't install Windows 8.1 on my Imac with Mavericks using Bootcamp. Why?

    I can't install Windows 8.1 on my Imac 27" with Mavericks using Bootcamp. Why? I first did all the software updates needed, downloaded the driver software to a 32Gb flash drive formatted as FAT32, fired up Bootcamp Assistant, inserted the Windows 8.1 Full version 64 bit installation DVD as requested, and got as far as partitioning (tried this at 82 Gb for the Windows partition), then the MAC rebooted but halted before getting to the login page. Then a black screen came up with the error message: 'non-system disk - Press any key to reboot'. I did this and nothing happened. I was forced to shut down forcibly then restart with my finger held down on the option key. Then a screen came up with two icons: the macintosh HD icon and the Windows DVD icon. I double-clicked on the Windows DVD icon and the MAC came up with another black screen and error message: 'CDBoot: Couldn't find BOOTMGR'. Had to shut down forcibly again and restart as before, this time ejecting the Windows DVD first. Then I repartitioned my MAC back to all OSX. What the **** do I do now? Applecare couldn't help me beyond this point. They said to contact Microsoft. I notice a lot of other MAC owners have had similar problems.
    Please help? tagjsmith.

    bootcamp does not currently support windows 8.1

  • IOS 5 used to allow Airplay between iPad (WiFi) and Apple TV (Ethernet) as long as they were on the same network. In iOS 6, now both the iPad and the Apple TV have to be on the same network and both have to be connected using WiFi ? Why did they change ?

    iOS 5 used to allow Airplay between iPad (WiFi) and Apple TV (Ethernet) as long as they were on the same network, i.e. connected to the same wired/wireless router. In iOS 6, now both the iPad and the Apple TV have to be on the same network and both have to be connected using WiFi ? Why did they change this ? Means that the iPad and the Apple TV box both have to be in range of the wireless router when this wasn't a restriction before. Apple TV could be anywhere as long as it was connected to the same wireless router via ethernet cable. Seems like an unnecessary thing to restrict.

    I have found with AppleTV that it is the IPV6 on the computer you want to access is the problem.  The issue is that Homegroup on Win 7 or Win 8 requires IPV6 to work, but AppleTV won't work with IPV6.  (So maybe double check you have IPV6 turned off)
    So you have to make a choice - Homegroup or AppleTV.... but you can't have both, until Apple brings ATV up to date. (crazy that it does not recognise IPV6 - c'mon Apple!)
    You can set up sharing individually in Win 7 or 8 and have the ATV access files that way.
    Having said that, there is always the exception.. I have an old HP home server running Win8 and it services ATV - but is part of the Homegroup... have no idea why it works on both, but no other machine on the home network will talk to both ATV and Homegroup at the same time!

  • I like to know when i use fire fox why it take so much resource of my computer ? it almost 1/4 of my 4gig of memeory , ihave 6,7 page of firefox window open

    i like to know when i use fire fox why it take so much resource of my computer ? it almost 1/4 of my 4 gig of memory , i have 6,-8 page of firefox window open at cpu level its is almost 25% been used up. i see its taking too much resource i wonder why ?? how not to take so much and it crashes often.. any help,ive 24.0 ,

    Firefox add-ons take some memory. This amount varies depending on the add-on.
    '''Try Firefox Safe Mode''' to see if the problem goes away. Safe Mode is a troubleshooting mode, which disables most add-ons.
    ''(If you're not using it, switch to the Default theme.)''
    * On Windows you can open Firefox 4.0+ in Safe Mode by holding the '''Shift''' key when you open the Firefox desktop or Start menu shortcut.
    * On Mac you can open Firefox 4.0+ in Safe Mode by holding the '''option''' key while starting Firefox.
    * On Linux you can open Firefox 4.0+ in Safe Mode by quitting Firefox and then going to your Terminal and running: firefox -safe-mode (you may need to specify the Firefox installation path e.g. /usr/lib/firefox)
    * Or open the Help menu and click on the '''Restart with Add-ons Disabled...''' menu item while Firefox is running.
    [[Image:FirefoxSafeMode|width=520]]
    ''Once you get the pop-up, just select "'Start in Safe Mode"''
    [[Image:Safe Mode Fx 15 - Win]]
    '''''If the issue is not present in Firefox Safe Mode''''', your problem is probably caused by an extension, and you need to figure out which one. Please follow the [[Troubleshooting extensions and themes]] article for that.
    ''To exit the Firefox Safe Mode, just close Firefox and wait a few seconds before opening Firefox for normal use again.''
    Does this decrease the memory usage? Please report back soon.

  • I have a 50.00 itunes balance and I am unable to use it.  Why is it requesting credit card info when I try abd purchase music?

    I have a 50.00 itunes balance and I am unable to use it.  Why is it requesting credit card info when I try to purchase music?  I've already redeemed my gift card onto my itunes account, so I no longer have a code. 

    Because your credit card info is how itunes verifies your account.

  • After las update some menus doesn't work properly. Ther is non possibility to use mouse. Why?

    After las update (9.2.1) some menus doesn't work properly. Ther is non possibility to use mouse. Why?

    Operating System?

  • HP 6500A Plus will not print black only if any color cartridges are low. It used to. Why not now?

    HP 6500A Plus will not print black only if any color cartridges are low. It used to. Why not now? It will print in color if the black is low but not if any color is low. This is very annoying. Printer is using HP cartridges too.

    Get used to this with HP printers - its a new feature they have introduced to keep running costs lows - works well. Had two HP printers same happened with both of these. Suggest a different brand - they might not have this special feature

  • N Mail, when using "reply all" why does Mail automatically include my email address in the cc line? Whey would I want to include my email address in an email I am sending.  Anybody have any idea how to stop this?

    In Mail, when using "reply all" why does Mail automatically include my email address in the cc line? Whey would I want to include my email address in an email I am sending.? Anybody have any idea how to stop Mail from including my email address in the cc line when using "reply all"?

    Automatically cc myself is not checked.  I did find out that if you have multiple email address that all of them need to be associated with "My Contact" tab.  Thanks

  • If RuneScape uses Java 3D why don't you need to install it?

    I was just wondering if RuneScape uses Java 3D, why doesn't anyone need to install it? Is it because the game is intirely server side and all the graphics and stuff is done over on their servers and not on your own computer? Thanks.

    Most likely, you have a web plugin that depends on the Java runtime distributed by Apple, such as the Facebook video calling plugin or the "NexDef" plugin for watching baseball streams. If you no longer need the plugin, remove it, including its automatic update mechanism (if any) according to the developer's instructions. Otherwise, install Java.

Maybe you are looking for

  • Warning message in Oracle Workflow notification

    Hi, I have a requirement, where a warning message is to be shown to the user when he presses the Approve button of a notification. I know that through post notification function, validations for a particular notification can be performed and an error

  • IMac display won't sleep with hot corner

    I saw that this question was asked before but no answer was given. I got my iMac OS X Yosemite 10.10 brand new yesterday. I set up hot corners so that the display will go to sleep when I swipe it. However, no matter how carefully I swipe, it always c

  • My home button stopped working

    It just doesn't  work anymore. I have a 5th gen blue ipod touch

  • Shared photo stream

    hi.  am trying to upload some photos to a shared photo stream.  on my mac, in iphoto, i have an event selected - when i 'share' to 'photo stream' and then select 'new photo stream', the photos whisk off to the left hand side of the screen into 'photo

  • Mobile PO / PR Releases

    I am trying to find the best solution for a client of mine to approve / reject / release PR's and PO's - I have identified 4 options, but would like advice as to which is the best way to go, if any... 1. www.go3i.com 2. www.10secondssoftware.com 3. S