<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>
<channel>
	<title>Comments on: How to turn rows into columns</title>
	<atom:link href="http://oraqa.com/2006/03/13/how-to-turn-rows-into-columns/feed/" rel="self" type="application/rss+xml" />
	<link>http://oraqa.com/2006/03/13/how-to-turn-rows-into-columns/</link>
	<description>Oracle Question and Answer</description>
	<pubDate>Thu, 20 Nov 2008 20:10:22 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.3</generator>
		<item>
		<title>By: Eddie Awad</title>
		<link>http://oraqa.com/2006/03/13/how-to-turn-rows-into-columns/#comment-176</link>
		<dc:creator>Eddie Awad</dc:creator>
		<pubDate>Wed, 12 Apr 2006 02:09:41 +0000</pubDate>
		<guid isPermaLink="false">http://oraqa.com/2006/03/13/how-to-turn-rows-into-columns/#comment-176</guid>
		<description>Deepak, you mean if the number of rows that we want to convert into columns is unknown or dynamic? In that case, We can dynamically construct the query that contains the CASE expressions, then execute the query (string) as dynamic SQL (using execute immediate). I have not tried it but theoretically it should work. 

More info at 

http://asktom.oracle.com/pls/ask/f?p=4950:8:::::F4950_P8_DISPLAYID:766825833740


Does the select list have a maximum number of columns?</description>
		<content:encoded><![CDATA[<p>Deepak, you mean if the number of rows that we want to convert into columns is unknown or dynamic? In that case, We can dynamically construct the query that contains the CASE expressions, then execute the query (string) as dynamic SQL (using execute immediate). I have not tried it but theoretically it should work. </p>
<p>More info at </p>
<p><a href="http://asktom.oracle.com/pls/ask/f?p=4950:8:::::F4950_P8_DISPLAYID:766825833740" rel="nofollow">http://asktom.oracle.com/pls/ask/f?p=4950:8:::::F4950_P8_DISPLAYID:766825833740</a></p>
<p>Does the select list have a maximum number of columns?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: deepak</title>
		<link>http://oraqa.com/2006/03/13/how-to-turn-rows-into-columns/#comment-175</link>
		<dc:creator>deepak</dc:creator>
		<pubDate>Tue, 11 Apr 2006 13:37:10 +0000</pubDate>
		<guid isPermaLink="false">http://oraqa.com/2006/03/13/how-to-turn-rows-into-columns/#comment-175</guid>
		<description>What if you do not know the value of the columns in advance?</description>
		<content:encoded><![CDATA[<p>What if you do not know the value of the columns in advance?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Karl Reitschuster</title>
		<link>http://oraqa.com/2006/03/13/how-to-turn-rows-into-columns/#comment-174</link>
		<dc:creator>Karl Reitschuster</dc:creator>
		<pubDate>Thu, 06 Apr 2006 17:10:22 +0000</pubDate>
		<guid isPermaLink="false">http://oraqa.com/2006/03/13/how-to-turn-rows-into-columns/#comment-174</guid>
		<description>Hi,
the simple case expression was released in 8.1
http://download-west.oracle.com/docs/cd/B10501_01/server.920/a96540/wnsql.htm#970400
Greetings
Karl</description>
		<content:encoded><![CDATA[<p>Hi,<br />
the simple case expression was released in 8.1<br />
<a href="http://download-west.oracle.com/docs/cd/B10501_01/server.920/a96540/wnsql.htm#970400" rel="nofollow">http://download-west.oracle.com/docs/cd/B10501_01/server.920/a96540/wnsql.htm#970400</a><br />
Greetings<br />
Karl</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Balqees</title>
		<link>http://oraqa.com/2006/03/13/how-to-turn-rows-into-columns/#comment-173</link>
		<dc:creator>Balqees</dc:creator>
		<pubDate>Sun, 02 Apr 2006 08:06:50 +0000</pubDate>
		<guid isPermaLink="false">http://oraqa.com/2006/03/13/how-to-turn-rows-into-columns/#comment-173</guid>
		<description>This was the error, and not the previous one:

select sum(case when job = 'ANALYST' then 1 else 0 end) as ANALYST,
                *
ERROR at line 1:
ORA-00907: missing right parenthesis</description>
		<content:encoded><![CDATA[<p>This was the error, and not the previous one:</p>
<p>select sum(case when job = &#8216;ANALYST&#8217; then 1 else 0 end) as ANALYST,<br />
                *<br />
ERROR at line 1:<br />
ORA-00907: missing right parenthesis</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Balqees</title>
		<link>http://oraqa.com/2006/03/13/how-to-turn-rows-into-columns/#comment-172</link>
		<dc:creator>Balqees</dc:creator>
		<pubDate>Sun, 02 Apr 2006 08:04:33 +0000</pubDate>
		<guid isPermaLink="false">http://oraqa.com/2006/03/13/how-to-turn-rows-into-columns/#comment-172</guid>
		<description>I tried the previous code to change rows into columns , but it did not work, I think it may work with later versions of sql.
Im using sql 8.0.

the code was:

SQL&#62; select  job, count(*) from emp
  2  group by job;

JOB        COUNT(*)
--------- ---------
ANALYST           2
CLERK             4
MANAGER           3
PRESIDENT         1
SALESMAN          4

SQL&#62; select sum(case when job = 'ANALYST' then 1 else 0 end) as ANALYST,
  2  sum(case when job = 'CLERK' then 1 else 0 end) as CLERK,
  3  sum(case when job = 'MANAGER' then 1 else 0 end) as MANAGER,
  4  sum(case when job = 'PRESIDENT' then 1 else 0 end) as PRESIDENT,
  5  sum(case when job = 'SALESMAN' then 1 else 0 end) as SALESMAN
  6  from (
  7  select job
  8  from emp
  9  where job in ('ANALYST', 'CLERK', 'MANAGER', 'PRESIDENT', 'SALESMAN'))
 10  /

But the ERROR was


select sum(case)when job = 'ANALYST' then 1 else 0 end) as ANLYST,
                     *
ERROR at line 1:
ORA-00923: FROM keyword not found where expected

I don't know what is the problem..</description>
		<content:encoded><![CDATA[<p>I tried the previous code to change rows into columns , but it did not work, I think it may work with later versions of sql.<br />
Im using sql 8.0.</p>
<p>the code was:</p>
<p>SQL&gt; select  job, count(*) from emp<br />
  2  group by job;</p>
<p>JOB        COUNT(*)<br />
&#8212;&#8212;&#8212; &#8212;&#8212;&#8212;<br />
ANALYST           2<br />
CLERK             4<br />
MANAGER           3<br />
PRESIDENT         1<br />
SALESMAN          4</p>
<p>SQL&gt; select sum(case when job = &#8216;ANALYST&#8217; then 1 else 0 end) as ANALYST,<br />
  2  sum(case when job = &#8216;CLERK&#8217; then 1 else 0 end) as CLERK,<br />
  3  sum(case when job = &#8216;MANAGER&#8217; then 1 else 0 end) as MANAGER,<br />
  4  sum(case when job = &#8216;PRESIDENT&#8217; then 1 else 0 end) as PRESIDENT,<br />
  5  sum(case when job = &#8216;SALESMAN&#8217; then 1 else 0 end) as SALESMAN<br />
  6  from (<br />
  7  select job<br />
  8  from emp<br />
  9  where job in (&#8217;ANALYST&#8217;, &#8216;CLERK&#8217;, &#8216;MANAGER&#8217;, &#8216;PRESIDENT&#8217;, &#8216;SALESMAN&#8217;))<br />
 10  /</p>
<p>But the ERROR was</p>
<p>select sum(case)when job = &#8216;ANALYST&#8217; then 1 else 0 end) as ANLYST,<br />
                     *<br />
ERROR at line 1:<br />
ORA-00923: FROM keyword not found where expected</p>
<p>I don&#8217;t know what is the problem..</p>
]]></content:encoded>
	</item>
</channel>
</rss>
