<?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"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Pivoting in SQL using the 10g Model Clause</title>
	<atom:link href="http://technology.amis.nl/blog/300/pivoting-in-sql-using-the-10g-model-clause/feed" rel="self" type="application/rss+xml" />
	<link>http://technology.amis.nl/blog/300/pivoting-in-sql-using-the-10g-model-clause</link>
	<description>Weblog for the AMIS Technology corner</description>
	<lastBuildDate>Fri, 10 Feb 2012 16:47:37 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Dinakar</title>
		<link>http://technology.amis.nl/blog/300/pivoting-in-sql-using-the-10g-model-clause/comment-page-1#comment-481292</link>
		<dc:creator>Dinakar</dc:creator>
		<pubDate>Tue, 11 Oct 2011 13:51:16 +0000</pubDate>
		<guid isPermaLink="false">/?p=300#comment-481292</guid>
		<description>Hi Lucas,
i tried using your pivoting logic to convert columns into rows, but i din&#039;t quite understand whats happening in the code though. can you please please explain or answer the below questions:
1.) why a partition was required in this case?
2.) why measures have to start with 0 hrs, why it should be defaulted?
3.) What is the model clause actually doing, can you please elaborate it step by step?
 
 </description>
		<content:encoded><![CDATA[<p>Hi Lucas,<br />
i tried using your pivoting logic to convert columns into rows, but i din&#8217;t quite understand whats happening in the code though. can you please please explain or answer the below questions:<br />
1.) why a partition was required in this case?<br />
2.) why measures have to start with 0 hrs, why it should be defaulted?<br />
3.) What is the model clause actually doing, can you please elaborate it step by step?<br />
 <br />
 </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Oliver</title>
		<link>http://technology.amis.nl/blog/300/pivoting-in-sql-using-the-10g-model-clause/comment-page-1#comment-42890</link>
		<dc:creator>Oliver</dc:creator>
		<pubDate>Wed, 30 Nov 2005 17:32:20 +0000</pubDate>
		<guid isPermaLink="false">/?p=300#comment-42890</guid>
		<description>How could I resolved the issue in which I don&#039;t know before hand the number of columns.  You know that you have mon, tue ... sun. How about if you are trying to convert 20 departments and you want to filter by dept ID but you need the Department Name as the column name.  The deparments filtered vary constantly so the names for the columns have to be according to the data extracted

Dept ID  Desc      Emps
10          Planning 3
10          Planning 3
15          Mktg      2
..
200        Call Center 5

I need an output
Planning  Mktg
6             2

another time
Planning Call Center
6             5</description>
		<content:encoded><![CDATA[<p>How could I resolved the issue in which I don&#8217;t know before hand the number of columns.  You know that you have mon, tue &#8230; sun. How about if you are trying to convert 20 departments and you want to filter by dept ID but you need the Department Name as the column name.  The deparments filtered vary constantly so the names for the columns have to be according to the data extracted</p>
<p>Dept ID  Desc      Emps<br />
10          Planning 3<br />
10          Planning 3<br />
15          Mktg      2<br />
..<br />
200        Call Center 5</p>
<p>I need an output<br />
Planning  Mktg<br />
6             2</p>
<p>another time<br />
Planning Call Center<br />
6             5</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Lucas</title>
		<link>http://technology.amis.nl/blog/300/pivoting-in-sql-using-the-10g-model-clause/comment-page-1#comment-1480</link>
		<dc:creator>Lucas</dc:creator>
		<pubDate>Thu, 16 Dec 2004 22:05:09 +0000</pubDate>
		<guid isPermaLink="false">/?p=300#comment-1480</guid>
		<description>From what I recently understood is that this may indicate that there was not enough memory space to hold the intermediate results and file swapping took place for the TEMP area. Can you somehow enlarge the memory available to this process?</description>
		<content:encoded><![CDATA[<p>From what I recently understood is that this may indicate that there was not enough memory space to hold the intermediate results and file swapping took place for the TEMP area. Can you somehow enlarge the memory available to this process?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: amihay gonen</title>
		<link>http://technology.amis.nl/blog/300/pivoting-in-sql-using-the-10g-model-clause/comment-page-1#comment-1479</link>
		<dc:creator>amihay gonen</dc:creator>
		<pubDate>Thu, 16 Dec 2004 20:20:43 +0000</pubDate>
		<guid isPermaLink="false">/?p=300#comment-1479</guid>
		<description>here is a performace test i&#039;ve maded on worked_hours.

insert into work_hours select mod(rownum,56),
rownum,mod(rownum,7),1 from dba_objects;

select count(1) from worked_hours;
   49647


select weekno
,      empno
,      mon
,      tue
,      wed
,      thu
,      fri
,      sat
,      sun
from   worked_hours
model
  return updated rows
  partition by (weekno, empno)
  dimension by ( day )
  measures ( hours, 0 mon, 0 tue, 0 wed, 0 thu, 0 fri, 0 sat, 0 sun)
  RULES upsert
  (
     mon [0] = hours [1]
   , tue [0] = hours [2]
   , wed [0] = hours [3]
   , thu [0] = hours [4]
   , fri [0] = hours [5]
   , sat [0] = hours [6]
   , sun [0] = hours [7]
  )
/

Statistics
----------------------------------------------------------
         10  recursive calls
          0  db block gets
        184  consistent gets
       1260  physical reads
          0  redo size
    1228664  bytes sent via SQL*Net to client
      36900  bytes received via SQL*Net from client
       3310  SQL*Net roundtrips to/from client
          0  sorts (memory)
          0  sorts (disk)
      49635  rows processed

49635 rows selected.

Elapsed: 00:00:04.21

SQL&gt; select weekno
  2  ,      empno
  3  ,      mon
  4  ,      tue
  5  ,      wed
  6  ,      thu
  7  ,      fri
  8  ,      sat
  9  ,      sun
 10  from   (
 11  select weekno,empno,sum(decode(day,2,hours,0)) mon,
 12  sum(decode(day,3,hours,0)) tue
 13  ,sum(decode(day,4,hours,0)) wed
 14  ,sum(decode(day,5,hours,0)) thu
 15  ,sum(decode(day,6,hours,0)) fri
 16  ,sum(decode(day,7,hours,0)) sat
 17  ,sum(decode(day,7,hours,0)) sun from
 18  worked_hours group by weekno,empno)
 19  /

49635 rows selected.

Elapsed: 00:00:01.92

Statistics
----------------------------------------------------------
          4  recursive calls
          6  db block gets
        184  consistent gets
        272  physical reads
          0  redo size
     943540  bytes sent via SQL*Net to client
      36900  bytes received via SQL*Net from client
       3310  SQL*Net roundtrips to/from client
          0  sorts (memory)
          1  sorts (disk)
      49635  rows processed



It seems that the old pivot method is better. It seems that the difference connect somehow to phiscal reads.</description>
		<content:encoded><![CDATA[<p>here is a performace test i&#8217;ve maded on worked_hours.</p>
<p>insert into work_hours select mod(rownum,56),<br />
rownum,mod(rownum,7),1 from dba_objects;</p>
<p>select count(1) from worked_hours;<br />
   49647</p>
<p>select weekno<br />
,      empno<br />
,      mon<br />
,      tue<br />
,      wed<br />
,      thu<br />
,      fri<br />
,      sat<br />
,      sun<br />
from   worked_hours<br />
model<br />
  return updated rows<br />
  partition by (weekno, empno)<br />
  dimension by ( day )<br />
  measures ( hours, 0 mon, 0 tue, 0 wed, 0 thu, 0 fri, 0 sat, 0 sun)<br />
  RULES upsert<br />
  (<br />
     mon [0] = hours [1]<br />
   , tue [0] = hours [2]<br />
   , wed [0] = hours [3]<br />
   , thu [0] = hours [4]<br />
   , fri [0] = hours [5]<br />
   , sat [0] = hours [6]<br />
   , sun [0] = hours [7]<br />
  )<br />
/</p>
<p>Statistics<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
         10  recursive calls<br />
          0  db block gets<br />
        184  consistent gets<br />
       1260  physical reads<br />
          0  redo size<br />
    1228664  bytes sent via SQL*Net to client<br />
      36900  bytes received via SQL*Net from client<br />
       3310  SQL*Net roundtrips to/from client<br />
          0  sorts (memory)<br />
          0  sorts (disk)<br />
      49635  rows processed</p>
<p>49635 rows selected.</p>
<p>Elapsed: 00:00:04.21</p>
<p>SQL> select weekno<br />
  2  ,      empno<br />
  3  ,      mon<br />
  4  ,      tue<br />
  5  ,      wed<br />
  6  ,      thu<br />
  7  ,      fri<br />
  8  ,      sat<br />
  9  ,      sun<br />
 10  from   (<br />
 11  select weekno,empno,sum(decode(day,2,hours,0)) mon,<br />
 12  sum(decode(day,3,hours,0)) tue<br />
 13  ,sum(decode(day,4,hours,0)) wed<br />
 14  ,sum(decode(day,5,hours,0)) thu<br />
 15  ,sum(decode(day,6,hours,0)) fri<br />
 16  ,sum(decode(day,7,hours,0)) sat<br />
 17  ,sum(decode(day,7,hours,0)) sun from<br />
 18  worked_hours group by weekno,empno)<br />
 19  /</p>
<p>49635 rows selected.</p>
<p>Elapsed: 00:00:01.92</p>
<p>Statistics<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
          4  recursive calls<br />
          6  db block gets<br />
        184  consistent gets<br />
        272  physical reads<br />
          0  redo size<br />
     943540  bytes sent via SQL*Net to client<br />
      36900  bytes received via SQL*Net from client<br />
       3310  SQL*Net roundtrips to/from client<br />
          0  sorts (memory)<br />
          1  sorts (disk)<br />
      49635  rows processed</p>
<p>It seems that the old pivot method is better. It seems that the difference connect somehow to phiscal reads.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

