Why don't PIVOT clause works with aggregate TRIP of 11g function?
Hi all!I'm really confused as to what is considered an aggregate function in the context of the PIVOT clause in 11 g.
I've been playing with a lot of things related to collections lately and it took birth in 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 point, I'm sure we can all agree that the applicationSELECT NODE_LEVEL,
CAST(COLLECT(TREE_NODE(NODE_ID, NODE_VALUE)) AS TREE_NODES) AS NODES
FROM TEST_COLL
GROUP BY NODE_LEVEL;
perfectly valid is that the function of COLLECTION is an aggregation function according to the [Official Documentation | http://docs.oracle.com/cd/E11882_01/server.112/e10592/functions031.htm#i1271564]But then, one of the two following 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, these two withORA-56902: expect aggregate function inside pivot operation
Study further, I found the same behavior when you use the aggregate function in the PIVOT XMLAGG clause.Is this normal? And if this is the case, is there another way to get the result that I expected?
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 - Production
Thanks in advanceBest regards
Philippe
Most likely a bug. But you can work around it by using any other aggregate for this group is composed of a single line and apply collect a rotated value. Yes, the cost is double aggregation. And also there is another cost - you must create the service card member other aggreations such as 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.
Tags: Database
Similar Questions
-
Please tell me why this script does not 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's the script in my html document:
< embed src = "News2008Fall.pdf" width = '615' height = '3200' > < / embed > "
Edit: removed # phone
Works for me on Linux.
Your system details list does not display the Adobe Reader plugin, so you'll have to (re) install this program.See:
-
Why CRYSTAL_REPORT program does not work with windows Vista? __
Why CRYSTAL_REPORT program does not work with windows Vista?
http://www.Microsoft.com/Windows/compatibility/Windows-Vista/default.aspx
Windows Vista Compatibility Center
First thing to do is to check its Vista compatibility at the link above, and if not to see what patches/solutions are available from its manufacturer...
http://www.howtogeek.com/HOWTO/Windows-Vista/using-Windows-Vista-compatibility-mode/
If this is not Vista compatible, read the info on the link above.
It works for some programs, but not all.This applies to software programs, NOT hardware drivers.
If it's Vista compatible > uninstall it > Re-download/save to your desktop > right click on the setup.exe > run as admin.
See you soon.
Mick Murphy - Microsoft partner
-
Why pes 2012 does not work with me and my video card is 1699 MB Intel HD Graphics(core i3)?
Hello
You receive an error message?
Method 1:
You can update the drivers of graphics cards and check.
Updated a hardware driver that is not working properly
http://Windows.Microsoft.com/en-us/Windows7/update-a-driver-for-hardware-that-isn ' t-work correctly
Method 2:
You can also perform a clean boot and check if it works:
How to troubleshoot a problem by performing a clean boot in Windows Vista or in Windows 7
http://support.Microsoft.com/kb/929135
Note: after a repair, be sure to set the computer to start as usual as mentioned in step 7 in the Knowledge Base articleYou can also check out the link:
The problems of the game performance
http://Windows.Microsoft.com/en-us/Windows7/fixing-game-performance-problems
Diagnose problems running DirectX
http://Windows.Microsoft.com/en-us/Windows7/diagnosing-basic-problems-with-DirectX -
sick. Why can CS3 - I only work with a single sheet on the desk? I want to make a multi page document...
Use this ancient workaround:
-
Why Acrobat DC does not work with office 2016?
When Adobe's Acrobat PDFMaker DC component software plug-in work with office 2016?
Doesn't seem to work now, thanks for getting back with me.
-
Why don't these CD works on all devices?
About a week or two ago I installed this mp3 converter add-on. I had a few CD R had been for a year or two laying around and decided to burn CDs of music converter worked very well. I have played on my computer and in the car. Last week I went and bought a pack of ten of the same CD and burned 4 disks only to find out that they would play only on the computer but not in the car. Thinking that something might be tweaked with the discs I bought another pack of a different MFG to get the same result-will not play in car.
This really annoyed me. I don't see why these new discs play only on computer and not in the car.
Someone already has this problem and if yes was a way to fix it?
Thank youSorry, not a Firefox support question.
Try a support forum for your brand of software "burner" or a forum dealing with record to CDR media.
-
Why Flash Player does not work with Firefox for Android Beta?
I activated the plugins (not just tap to play, enable) under display settings, but when I try for example www.speedtest.net , told me that I don't have Flash installed. Flash works fine with Firefox for Android(non-beta), I can use www.speedtest.net very well. I have a Galaxy S4 I9505 running Stock Android 4.4.2 official Touchwiz. I hope that this problem can be solved! Thank you very much!
Hi haoyangw
Speedtest.NET works very well on my S5 Galaxy runs Android 4.4.2 (I don't have a Galaxy S4) on Firefox (release) 30 and 31 of Firefox (beta).
Please try:
1. try to reinstall flash2. try to disable the other modules you may have
If this does not help, you may have a bug. If you are technical please fill in a bug at bugzilla.org
Without worrying you please let us know if 1. and 2. above for help.
-
Why does Google search not work with FF14.0.1?
Google search on the Web does not. I can't use it at all. I'll give you photos as examples:
http://I20.Photobucket.com/albums/B232/emerald_typhoon/example1.jpg
However, if I use the image search, it works:
http://I20.Photobucket.com/albums/B232/emerald_typhoon/example2.jpg
Then he'll do the search on the Web if the text box has already done the research. You go to the top and click find beside the pictures, and the results will be displayed. I lived with a friend to see if it is a computer problem, and it happens on Fire Fox. Does anyone have an idea what could be the problem?
Have you tried to delete cookies for Google?
Clear the cache and cookies from sites that cause problems.
"Clear the Cache":
- Tools > Options > advanced > network > content caching Web: 'clear now '.
'Delete Cookies' sites causing problems:
- Tools > Options > privacy > Cookies: "show the Cookies".
Start Firefox in Safe Mode to check if one of the extensions or if hardware acceleration is the cause of the problem (switch to the DEFAULT theme: Firefox/tools > Modules > appearance/themes).
- Makes no changes on the start safe mode window.
- https://support.Mozilla.org/KB/safe+mode
You can also do a check of malware with some digitization programs of malicious software on the Windows computer.
You need to scan with all programs, because each program detects a different malicious program.
Make sure that you update each program to get the latest version of their databases before scanning.- http://www.malwarebytes.org/mbam.php - Malwarebytes' Anti-Malware
- http://www.superantispyware.com/ - SuperAntispyware
- http://www.microsoft.com/security/scanner/en-us/default.aspx - scan Microsoft Security
- http://www.microsoft.com/windows/products/winfamily/defender/default.mspx - Windows Defender: Home Page
- http://www.safer-networking.org/en/index.html - Spybot Search & Destroy
Alternatively, you can write a check for an infection rootkit TDSSKiller.
See also:
- "Spyware on Windows": http://kb.mozillazine.org/Popups_not_blocked
-
Why FileUtils::CopyFile does not work with empty space?
Hi all
If I have a destination directory with empty space inside, like: "C:\Users\Pattrick James\Documents" for Windows or "Macintosh HD:Users:Pattrick James: Documents" for Mac.
So I want to copy a file in this directory, use FileUtils::CopyFile (src, a). Why it does not work?
Can someone please help me to resolve this problem without change my way?
Sorry, it works fine. It happens because the directory permission.
-
Why my keyboard does not work with firefox?
I uninstalled and then reinstalled the latest version of firefox, but I still have the same problem - I am not able to type anything in the url or the google search field.
I am able to type in other programs on my computer but
Some have reported that pressing F9 and the main windows one or more times worked to solve problems with the keyboard not working do not.
-
Why my printer does not work with a second laptop?
I have 2 laptops Asus X55U.
No problem with the printer printing from my computer, but it will not print to my wife's computer.
I have a HP Deskjet 4280.
Before printing, the "Devices and printers" page on each of the laptops has a green check mark in the lower left corner of the printer icon.
When I click on 'Print' on the page to print, HP page rises and now says "printing" but nothing happens.I fixed it myself.
I uninstalled the printer on two laptop computers and re-installed.
Whatever the problem, it's the printer now works on both computers.
Thank you very much for your work on this.
It is greatly appreciated. -
Why Norton Toolbar will not work with Firefox 23.0.1?
Norton Toolbar 2013.4.1.2 is disabled and there is no option to turn it on. I've updated my Norton 360 with all latest updates. Norton site says that it has updated its software to be compatible with Firefox 23.
Thank you in advance,
LarreyFinally solved my problem. I had to uninstall and reinstall Norton 360 and when I updated and rebooted I had the last Norton Toolbar, v2012.4.2.2
For some reason any before the re-setup of Norton 360 my Norton Toolbar would not be up to date to the latest version. V2012.4.1.2 Norton Toolbar is not compatible with Firefox v23.0.1
At least now I have my Norton Toolbar with Firefox.
-
Google don't play not work with mobile network
I can't download or update any application when I am connected to the mobile network
After talking with support Center, I reset all the preferences app (app settings/applications/reset preferences) and restarted the machine. He started to download! Problem solved so far...
-
Why don't G510n print photos with premium photo paper
I just got the G510n Wireless for Christmas. I tried to print a Photo on Photo Premium paper and she doesn't. I can not find Photo ink for this printer. This printer does not have the ability to print Photos on Photo paper?
HI Dawn3905,
Yes, your printer has the ability to print photos on photo paper.
I do not know what operating system you are using, but here is a link that shows how to print using paper photo under Mac OS 10.5 or later.
Also here a link to the manual of your printers with instructions on how to print photos on windows as well.
Hope it will be useful.
Maybe you are looking for
-
Skype does not clearly indicate my mob
I am happy
-
4.4.3 and 4.4.4 updated India motorcycle g
Hi all I would like to ask when we in India will get the update 4.4.3 and 4.4.4 for motorcycle G (XT1033). Thank you
-
Install Windows XP on a Virtual Machine in Windows 8
I tried to clone an installation of Windows XP on a DELL portable computer that almost died of old age in a Virtual Machine on my new computer Windows 8. Windows 8 will not work some software I need and that you've used for years on the old laptop.
-
How can I save my new laptop?
Original title: new computer often asked back up... settings? the lower display righ t I keep getting invited to back up with cd, it is a new laptop. What is my settings?
-
Issues of privacy about the instant ink HP
I have read the terms of USE and learned that HP monitors the level of ink, page counts and type of printed documents. Do they get access to the documents I print? It would be a serious privacy violation.