Home » SQL & PL/SQL » SQL & PL/SQL » Query (Oracle 11g)
icon5.gif  Query [message #645273] Wed, 02 December 2015 01:09 Go to next message
kashif.masood.hashmi
Messages: 1
Registered: April 2012
Location: Karachi,Pakistan
Junior Member

I am using following Query
SELECT * FROM
(
SELECT job, deptno,sal
FROM emp
)
PIVOT
(
SUM(SAL)
FOR deptno IN (select to_char(wm_concat(deptno)) from dept)
)
ORDER BY job

Its generate error, But when i fixed the value in For deptno in (10,20,30) its run and generate output.
I do not want to fix the value..
Any Solution Please
Re: Query [message #645278 is a reply to message #645273] Wed, 02 December 2015 02:34 Go to previous messageGo to next message
Michel Cadot
Messages: 68645
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

You cannot use a SELECT in the IN clause of PIVOT (unless you use the XML option).

In addition, you should NEVER use "wm_concat" which is for Oracle internal use only and no more exists in 12c. As you are in 11g you can use listagg instead (this is a general answer, you cannot use it for your current issue).

[Updated on: Wed, 02 December 2015 02:35]

Report message to a moderator

Re: Query [message #645286 is a reply to message #645273] Wed, 02 December 2015 05:29 Go to previous messageGo to next message
Lalit Kumar B
Messages: 3174
Registered: May 2013
Location: World Wide on the Web
Senior Member
Hi,

Welcome to the forum!

Apart from the technicalities that Michel has mentioned, please read and follow the OraFAQ Forum Guide and How to use [code] tags.

Also, choose a better topic title than naming it as "Query".

[Updated on: Wed, 02 December 2015 05:34]

Report message to a moderator

Re: Query [message #645287 is a reply to message #645273] Wed, 02 December 2015 05:33 Go to previous message
Lalit Kumar B
Messages: 3174
Registered: May 2013
Location: World Wide on the Web
Senior Member
A quick google search brought up these links where this has been already discussed a lot of times:

https://community.oracle.com/thread/2183084
https://asktom.oracle.com/pls/asktom/f?p=100:11:0::NO::P11_QUESTION_ID:5312784100346298561

It covers the XML examples which Michel has suggested.
Previous Topic: Flattening out a table
Next Topic: get 7 working day excluding holidays in Oracle
Goto Forum:
  


Current Time: Fri Apr 26 06:56:47 CDT 2024