Why doesn't PIVOT clause work with COLLECT aggregate function in 11g ?

Hello all !
I am really puzzled as to what is considered an aggregate function in the context of the PIVOT clause in 11g.
I have been toying with quite a few things related to collections lately and this arose as an aside :
CREATE TABLE TEST_COLL
   NODE_ID    VARCHAR2(15 CHAR) NOT NULL,
   NODE_VALUE VARCHAR2(45 CHAR) NOT NULL,
   NODE_LEVEL NUMBER(1)         NOT NULL
CREATE OR REPLACE TYPE TREE_NODE AS OBJECT
   NODE_KEY  VARCHAR2( 15 CHAR),
   NODE_NAME VARCHAR2(127 CHAR)
CREATE OR REPLACE TYPE TREE_NODES AS TABLE OF TREE_NODE NOT NULL;At this stage I am sure we all agree that the query
SELECT NODE_LEVEL,
       CAST(COLLECT(TREE_NODE(NODE_ID, NODE_VALUE)) AS TREE_NODES) AS NODES
  FROM TEST_COLL
GROUP BY NODE_LEVEL;is perfectly valid as the COLLECT function is an aggregate function according to the [Official Documentation|http://docs.oracle.com/cd/E11882_01/server.112/e10592/functions031.htm#i1271564]
But then, one of the following two queries should work
SELECT CAST(REGION_NODES     AS TREE_NODES) AS REGIONS,
       CAST(DEPARTMENT_NODES AS TREE_NODES) AS DEPARTMENTS,
       CAST(AREA_NODES       AS TREE_NODES) AS AREAS,
       CAST(CENTRE_NODES     AS TREE_NODES) AS CENTRES
  FROM (SELECT NODE_LEVEL, TREE_NODE(NODE_ID, NODE_VALUE) AS NODE
          FROM TREE_COLL
PIVOT (COLLECT(NODE) FOR NODE_LEVEL IN (1 AS REGION_NODES,
                                         2 AS DEPARTMENT_NODES,
                                         3 AS AREA_NODES,
                                         4 AS CENTRE_NODES
or (better)
SELECT REGION_NODES     AS REGIONS,
       DEPARTMENT_NODES AS DEPARTMENTS,
       AREA_NODES       AS AREAS,
       CENTRE_NODES     AS CENTRES
  FROM (SELECT NODE_LEVEL, TREE_NODE(NODE_ID, NODE_VALUE) AS NODE
          FROM TREE_COLL
PIVOT (CAST(COLLECT(NODE) AS TREE_NODES) FOR NODE_LEVEL IN (1 AS REGION_NODES,
                                                             2 AS DEPARTMENT_NODES,
                                                             3 AS AREA_NODES,
                                                             4 AS CENTRE_NODES
       );yet, both fail with
ORA-56902: expect aggregate function inside pivot operationInvestigating further, I found the same behaviour when using XMLAGG as the aggregate function in the PIVOT clause.
Is this normal ? And if it is, is there any other way to achieve the result I was anticipating ?
My version is
SQL> SELECT BANNER FROM V$VERSION;
BANNER
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
PL/SQL Release 11.2.0.3.0 - Production
CORE    11.2.0.3.0      Production
TNS for 64-bit Windows: Version 11.2.0.3.0 - Production
NLSRTL Version 11.2.0.3.0 - ProductionThanks in advance
Best Regards
Philip

Most likely a bug. But you can bypass it by using any other aggregate making sure group consists of a single row and apply collect to a pivoted value. Yes, the cost is double aggregation. And also there is another cost - you would need to create MAP member function otherwise aggreations like MAX/MIN, etc. will not work:
CREATE OR REPLACE TYPE TREE_NODE AS OBJECT
   NODE_KEY  VARCHAR2( 15 CHAR),
   NODE_NAME VARCHAR2(127 CHAR),
   map member function f return varchar2
Type created.
CREATE OR REPLACE TYPE BODY TREE_NODE AS
  map member function f return varchar2 is
  begin
     return NODE_NAME;
  end f;
end;
Type body created.
CREATE OR REPLACE TYPE TREE_NODES AS TABLE OF TREE_NODE NOT NULL
Type created.
SQL> select  *
  2    from  test_coll
  3  /
NODE_ID NODE_VALUE NODE_LEVEL
1       A                   1
2       B                   2
3       C                   3
4       D                   4
5       E                   1
6       F                   2
7       G                   3
8       H                   4
8 rows selected.
SQL> Now:
SELECT CAST(COLLECT(REGION_NODES)     AS TREE_NODES) AS REGIONS,
       CAST(COLLECT(DEPARTMENT_NODES) AS TREE_NODES) AS DEPARTMENTS,
       CAST(COLLECT(AREA_NODES)       AS TREE_NODES) AS AREAS,
       CAST(COLLECT(CENTRE_NODES)     AS TREE_NODES) AS CENTRES
  FROM (
        SELECT  ROWID RID,
                NODE_LEVEL,
                TREE_NODE(NODE_ID, NODE_VALUE) AS NODE
          FROM  TEST_COLL
PIVOT (MAX(NODE) FOR NODE_LEVEL IN (
                                     1 AS REGION_NODES,
                                     2 AS DEPARTMENT_NODES,
                                     3 AS AREA_NODES,
                                     4 AS CENTRE_NODES
REGIONS(NODE_KEY, NODE_NAME)                         DEPARTMENTS(NODE_KEY, NODE_NAME)                     AREAS(NODE_KEY, NODE_NAME)                           CENTRES(NODE_KEY, NODE_NAME)
TREE_NODES(TREE_NODE('1', 'A'), TREE_NODE('5', 'E')) TREE_NODES(TREE_NODE('6', 'F'), TREE_NODE('2', 'B')) TREE_NODES(TREE_NODE('7', 'G'), TREE_NODE('3', 'C')) TREE_NODES(TREE_NODE('8', 'H'), TREE_NODE('4', 'D'))
SQL> SY.

Similar Messages

  • Why doesn't Image Capture work with document feeders?

    I've tried to scan a bunch of different types of documents using Image Capture and my Samsung CLX-3175FW's document feeder (multifunction color laser printer) but every time what gets scanned is a thin vertical slice of each page - completely useless. I don't see any way to force Image Capture to scan at 8.5" x 11" rather than doing whatever it's doing resulting in a thin vertical slice.
    Any ideas on how to fix this?
    Thanks!

    Quick update... I've done some troubleshooting and confirmed that when Image Capture scanning via USB and using the document feeder, everything looks great. When the ONLY option I change is printing via wireless, I get the thin vertical slice of each page. I sent some screenshots to Samsung to see if they have any ideas.

  • How JAVA works with collection from function

    All,
    I have a DB function which returns object collection of values. Could someone please tell me how java talks with the function and get the value?
    Thanks

    This is database function. my question is how java get those values from the function.
    Could you please post some sample code also?
    CREATE OR REPLACE
    Type T_PREO_RoleINFO is Object
    ROLE_ID NUMBER(10),
    ROLE_NAME VARCHAR2(20))
    CREATE OR REPLACE
    TYPE T_RoleInfo IS TABLE OF PREORDER.
    T_PREO_RoleINFO
    Function F_GetUserRole(Userid in number)
    return T_RoleInfo as
    V_Role T_RoleInfo;
    begin
         select T_PREO_RoleINFO(PREO_Role.ROLE_ID,PREO_Role.ROLE_NAME)
         BULK COLLECT INTO V_Role
         from preorder.PREO_Role, preorder.PREO_User_Role
         where PREO_Role.Role_id = PREO_User_Role.Role_id
         and PREO_User_Role.user_id = userid;
         return V_Role;
    end;

  • Can someone tell me why a standard microphone doesn't seem to work with a mac-mini? Is there another kind of microphone I need to use?

    can someone tell me why a standard microphone doesn't seem to work with a mac-mini? Is there another kind of microphone I need to use?

    Most microphone output a low voltage signal that must be put through a preamp.
    The computer needs to have a line voltage signal level instead.
    Allan

  • Why doesn't this update work?

    Why doesn't this update work? Can't I sum up two select count(*) in such a subquery?
    Thanks
    update sales T
    set T.field2 = ((select count(*)
    from sales t
    where t.field1 = trunc(sysdate)) + (select count((*)
    from sales t2
    where t2.field2 is null));
    I get
    ERROR at line 4:
    ORA-00907: missing right parenthesis
    with the * under the +
    In other words I want to run
    update sales set field = ((select count(*) ..... ) + (select count(*) ..... ))
    Edited by: Mark1970 on 26-mar-2010 1.37
    Edited by: Mark1970 on 26-mar-2010 1.38

    My problem is to undestand why I got a syntax error about parenthesis.Because you cannot perform arithmatic operation with a value coming from a subquery in a SET clause of UPDATE
    SQL> update emp
      2  set sal=(select 1 from dual)+1;
    set sal=(select 1 from dual)+1
    ERROR at line 2:
    ORA-00933: SQL command not properly ended
    SQL> select sal from emp
      2  where deptno=(select 10 from dual)+10;
           SAL
           800
          2975
          3000
          1100
          3000
    SQL>  select deptno,sal from emp
      2   where deptno=(select 10 from dual)+10;
        DEPTNO        SAL
            20        800
            20       2975
            20       3000
            20       1100
            20       3000Try such few examples..
    Twinkle

  • Why won't my iMessage work with only one contact in my phone all my other iMessages send and they just got an iphone but all their iMessages are sending also. I've tried restarting my phone, deleting messages, contact, restarting network

    Why won't my iMessage work with only one contact in my phone all my other iMessages send and they just got an iphone but all their iMessages are sending also. I've tried restarting my phone, deleting messages, contact, restarting network

    Hello Jesslb23,
    Thanks for using Apple Support Communities.
    For more information on this, take a look at:
    iOS: Troubleshooting Messages
    http://support.apple.com/kb/ts2755
    To resolve issues with sending and receiving iMessages, follow these steps first
    Check iMessage system status for current service issues.
    Go to Settings > Messages > Send & Receive and make sure that you have registered iMessage with your phone number or Apple ID and that you have selected iMessage for use. Learn more about troubleshooting iMessage registration if the phone number or Apple ID isn't available for use.
    Open Safari and navigate to www.apple.com to verify data connectivity. Learn more about troubleshootingcellular data or a Wi-Fi connection if a data connection isn't available.
    iMessage over cellular data might not be available while on a call. Only 3G and faster GSM networks support simultaneous data and voice calls. Learn more about which network your phone supports. Go to Settings > Wi-Fi and turn Wi-Fi on to use iMessage while on a call if your network doesn't support simultaneous data and voice calls.
    Restart your device.
    Tap Settings > General > Reset > Reset Network Settings on your iPhone.
    If you are still unable to send or receive an iMessage, follow these steps
    Make sure that the contact trying to message you isn't blocked in Settings > Messages > Blocked.
    Verify that the contact you are attempting to send a message to is registered with iMessage.
    If the issue occurs with a specific contact or contacts, back up or forward important messages and delete your current messaging threads with the contact. Create a new message to the contact and try again.
    If the issue occurs with a specific contact or contacts, delete and re-create the contact in the Contacts application. Create a new message to the newly created contact and try again.
    Back up and restore your device as new.
    Best of luck,
    Mario

  • Why does my ipad air work with my netgear routerWGT624

    why does my ipad air work with my netgear routerWGT 624

    Why wouldn't it work with that router?
    Or are you really asking why doesn't it work with that router? If that's your question try rebooting the router by powering it off for thirty seconds then turning it back on.
    If this doesn't help please explain in more detail what happens when your iPad attempt to connect to your Wi-Fi network.

  • Why doesn't my timeline work in IE?

    I created this page with a basic timeline.  The timeline works in Firefox, Safari and Chrome but not in IE.  All my browsers are up to date. Any help would be appreciated!
    http://laartgallery.net/index2.html
    Thanks again,
    Steve

    Nancy; THANK YOU!!  OK..it still does not work but I see where there are a lot of errors. I changed the head tags and it still does not work but I would assume I can go to the site/page you sent and it analyzes webpages for errors?  I will keep at it til I get it right or maybe redo the page but thank you very much for your time...I truly appreciate it. Steve
    Steve Andrews
    [email protected]
    www.digital-tailoring.com
    215-493-8958
    Date: Sat, 3 Mar 2012 13:03:27 -0700
    From: [email protected]
    To: [email protected]
    Subject: Why doesn't my timeline work in IE?
        Re: Why doesn't my timeline work in IE?
        created by Nancy O. in Dreamweaver - View the full discussion
    Invalid code.  http://validator.w3.org/check?verbose=1&uri=http%3A%2F%2Flaartgallery. net%2Findex2.html You have multiple sets of &  tags in your document. Only one set is allowed.  Nancy O.Alt-Web Design & PublishingWeb | Graphics | Print | Media  Specialists  http://alt-web.com/http://twitter.com/altweb
         Replies to this message go to everyone subscribed to this thread, not directly to the person who posted the message. To post a reply, either reply to this email or visit the message page: http://forums.adobe.com/message/4243531#4243531
         To unsubscribe from this thread, please visit the message page at http://forums.adobe.com/message/4243531#4243531. In the Actions box on the right, click the Stop Email Notifications link.
         Start a new discussion in Dreamweaver by email or at Adobe Forums
      For more information about maintaining your forum email notifications please go to http://forums.adobe.com/message/2936746#2936746.

  • Is there a way of using IE7 with Mountain Lion? There used to be this facility using Safari "Develop" with Lion, but this doesn't seem to work with ML

    Is there a way of using IE7 with Mountain Lion? There used to be this facility using Safari "Develop" with Lion, but this doesn't seem to work with ML

    Thank you for this, and to Caleb.
    I've tried using Caleb's approach (which is the same as I used with Lion), but the programme doesn't respond now that I have installed Mountain Lion.
    My problem is that I do not want to use IE7 but that a programme I need regular access to will only allow IE7 and I've been told by the developers that it is too expensive to upgrade this programme to allow it to be used by other browsers.
    So, my puzzle remains the same. I could access IE7 and use the programme using Caleb's solution with Lion. I can't do the same with Mountain Lion. I do (I think!) understand your point about the programme requiring IE7 specifically, but if it worked on Lion, why isn't it working on Mountain Lion? Or was I just lucky before?
    I'll try mende1's approach, though I doubt I'm technical enough to virtualise anything!
    Thanks again. Any further thoughts welcome.

  • Why won't this scriipt work with Firefox? embed src="News2008Fall.pdf" width="615" height="3200" /embed

    Please tell me why this script won't work with Firefox. It works with Safari. Here is the page that includes the script: www.lionsgatehoa.org/newslettertest.html. Thank you. Tom Engleman
    Here is the script in my html document:
    <embed src="News2008Fall.pdf" width="615" height="3200"></embed>
    edit: removed phone #

    Works for me on Linux.<br />
    Your system details list doesn't show the Adobe Reader plugin, so you will have to (re)install that program.
    See:
    *https://support.mozilla.org/kb/Using+the+Adobe+Reader+plugin+with+Firefox
    *http://kb.mozillazine.org/Adobe_Reader
    *http://get.adobe.com/reader/otherversions/

  • Why LR4.4 no longer works with Blurb?

    Hi,
    why LR4.4 no longer works with Blurb?
    If I configure a book and then click Submit to Blurb does not happen anymore. I even looked at the network traffic and it seems as if the IP is pinged to the contact record no longer respond. I do not understand. This has worked fine all the time. On the computer no setting has been changed. No software is installed that would prevent something. The last book has worked wonderfully. Interesting things, when I export the book as PDF and then upload at Blurb, Blurb complains that the standard by which PDF is not true. X2003 PDF version .... but I am surprised very strong and I really suspect that there adobe wants to put a stop to that one is supposed to buy the new LR version. But everything just a guess. Maybe someone can help me or even has a similar problem.
    greeting
    Mario.

    Try:
    - Reset the iOS device. Nothing will be lost
    Reset iOS device: Hold down the On/Off button and the Home button at the same time for at
    least ten seconds, until the Apple logo appears.
    - Reset all settings      
    Go to Settings > General > Reset and tap Reset All Settings.
    All your preferences and settings are reset. Information (such as contacts and calendars) and media (such as songs and videos) aren’t affected.
    - Restore from backup. See:                                 
    iOS: How to back up           
    - Restore to factory settings/new iOS device.
    If not successful that means that the IOS update broke compatibility, Since the 3G and 4G iPods has difference hardware, there are some differences in the iOSs for the two model iPod.

  • Why Oracle 8i is not Working with JDK 1.3

    Why Oracle 8i is not Working with JDK 1.3 by using JDBC.

    try this
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection con = DriverManager.getConnection("jdbc:odbc:"somedsn","scott","tiger");
    I am using this for Oracle, it is working for me.
    Uma
    Java Developer
    http://www.globalleafs.com

  • Why does Server Monitor not work with non-Xserves?

    Does anyone know why Server Monitor does not work with non-Xserve computers? We acquired a Power Mac for a server, based on there being no apparent difference except for the obvious. Turns out there are some differences after all.
    Do Power Macs lack some hardware components or is this just a software thing?

    God question, unfortunitly I dont have the answer but I would also like to know why the software only works for X-Serve....Is there any 3rd Party Software that is similar to "Server Monitor"?
    Thanks

  • Why does my imessage not work with only 1 phone number

    Why does my imessage not work with only 1 phone number? It keeps going to imessage and then back to text message

    Both you and the recipient have to have active data connections, and both devices have to have iOS 5 or higher to be able to use iMessage. Also, they both have to have iMessage activated. If that is already the case, there is a possiblility that iMessage is down. It has gone up and down several times in the past week. Check this page for status, and if necessary you can report a problem with a link in the lower right corner. http://www.apple.com/support/icloud/systemstatus/

  • Why does flash player not work with facebook?

    Why does flash player not work with fcebook?  Whenever I wish to view a video, I get the message that i need to upgrade my flash player. Then no matter how often I download and install flash player I still get the message that I need to upgrade my flash player.  When I go check which version I have, I always get the message that I have the most current one.  I run Mozilla Firefox with Windows.  I don't know anything else.
    Message was edited by: khettich

    This means you don't have the latest version installed.  Update to 11.9.900.117, and Firefox will allow it: Flash Player Plug-in (All other browsers)

Maybe you are looking for

  • If it is not specified,Oracle creates one control file in a default locatio

    Hi The CONTROL_FILES parameter is not required when you create a database. If it is not specified,Oracle creates one control file in a default location,. Where oracle create contol file default in this condition Thanks

  • Base unit of measure Box is missing in SAP 4.7

    Dear Group members Base Unit of Measure "Box " is not in my SAP System 4.7 Dear Group Member I am not finding "Box " Base Unit of Measure in my system My system is SAP 4.7 You suggestions will be appreciated

  • Track as intruder ??

    What does this function actually do ???

  • WebOS 1.4 bug report - Shared youtube video ids are sometimes undefined

    When I upload a video to YouTube and then select the option to share it by email, I frequently find that the generated URL is "http://www.youtube.com/watch?v=undefined". Apparently it isn't getting back the video id from youtube when it expects to.

  • JSPM folder is missing

    Dear All, I have installed WAS Java add IN on WAS ABAP on mysap ecc5 windows based server with oracle 9i database . I have to install some java patches through JSPM but there is no JSPM folder is exist , how I can install it . Pl. help me Thanks Sand