<?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: SQL*Plus or Report style Break Groups in SQL Query</title>
	<atom:link href="http://technology.amis.nl/2005/09/22/sqlplus-or-report-style-break-groups-in-sql-query/feed/" rel="self" type="application/rss+xml" />
	<link>http://technology.amis.nl/2005/09/22/sqlplus-or-report-style-break-groups-in-sql-query/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=sqlplus-or-report-style-break-groups-in-sql-query</link>
	<description></description>
	<lastBuildDate>Fri, 12 Apr 2013 10:04:09 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
	<item>
		<title>By: Alex Nuijten</title>
		<link>http://technology.amis.nl/2005/09/22/sqlplus-or-report-style-break-groups-in-sql-query/#comment-2446</link>
		<dc:creator>Alex Nuijten</dc:creator>
		<pubDate>Fri, 23 Sep 2005 09:20:42 +0000</pubDate>
		<guid isPermaLink="false">/?p=805#comment-2446</guid>
		<description><![CDATA[I just did a trace on the two different queries, and here&#039;s the result: (actually I did the trace twice)
********************************************************************************

select ename
     , case Row_Number() over (partition by deptno
                              order by null
                          )
       when 1
       then deptno
       end
  from t

call     count       cpu    elapsed       disk      query    current        rows
------- ------  -------- ---------- ---------- ---------- ----------  ----------
Parse        2    166.66     286.72          0        124          0           0
Execute      2      0.00     143.36          0          0          0           0
Fetch        4      0.00     153.60          0          6          0          28
------- ------  -------- ---------- ---------- ---------- ----------  ----------
total        8    166.66     583.68          0        130          0          28

Misses in library cache during parse: 2
Optimizer goal: CHOOSE
Parsing user id: 21

Rows     Row Source Operation
-------  ---------------------------------------------------
     14  WINDOW SORT
     14   TABLE ACCESS FULL T

********************************************************************************
********************************************************************************

select ename
,      case rn
       when 1
       then deptno
       end  deptno
from   ( select ename
         ,      deptno
         ,      row_number() over (partition by deptno order by null) rn
         from   t
       )

call     count       cpu    elapsed       disk      query    current        rows
------- ------  -------- ---------- ---------- ---------- ----------  ----------
Parse        2      0.01     215.04          0          5          0           0
Execute      2      0.00       0.00          0          0          0           0
Fetch        4      0.00       0.00          0          6          0          28
------- ------  -------- ---------- ---------- ---------- ----------  ----------
total        8      0.01     215.04          0         11          0          28

Misses in library cache during parse: 2
Optimizer goal: CHOOSE
Parsing user id: 21

Rows     Row Source Operation
-------  ---------------------------------------------------
     14  VIEW
     14   WINDOW SORT
     14    TABLE ACCESS FULL T

********************************************************************************

I seems to me that the in-line view wins hands down!]]></description>
		<content:encoded><![CDATA[<p>I just did a trace on the two different queries, and here&#8217;s the result: (actually I did the trace twice)<br />
********************************************************************************</p>
<p>select ename<br />
     , case Row_Number() over (partition by deptno<br />
                              order by null<br />
                          )<br />
       when 1<br />
       then deptno<br />
       end<br />
  from t</p>
<p>call     count       cpu    elapsed       disk      query    current        rows<br />
&#8212;&#8212;- &#8212;&#8212;  &#8212;&#8212;&#8211; &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;-  &#8212;&#8212;&#8212;-<br />
Parse        2    166.66     286.72          0        124          0           0<br />
Execute      2      0.00     143.36          0          0          0           0<br />
Fetch        4      0.00     153.60          0          6          0          28<br />
&#8212;&#8212;- &#8212;&#8212;  &#8212;&#8212;&#8211; &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;-  &#8212;&#8212;&#8212;-<br />
total        8    166.66     583.68          0        130          0          28</p>
<p>Misses in library cache during parse: 2<br />
Optimizer goal: CHOOSE<br />
Parsing user id: 21</p>
<p>Rows     Row Source Operation<br />
&#8212;&#8212;-  &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
     14  WINDOW SORT<br />
     14   TABLE ACCESS FULL T</p>
<p>********************************************************************************<br />
********************************************************************************</p>
<p>select ename<br />
,      case rn<br />
       when 1<br />
       then deptno<br />
       end  deptno<br />
from   ( select ename<br />
         ,      deptno<br />
         ,      row_number() over (partition by deptno order by null) rn<br />
         from   t<br />
       )</p>
<p>call     count       cpu    elapsed       disk      query    current        rows<br />
&#8212;&#8212;- &#8212;&#8212;  &#8212;&#8212;&#8211; &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;-  &#8212;&#8212;&#8212;-<br />
Parse        2      0.01     215.04          0          5          0           0<br />
Execute      2      0.00       0.00          0          0          0           0<br />
Fetch        4      0.00       0.00          0          6          0          28<br />
&#8212;&#8212;- &#8212;&#8212;  &#8212;&#8212;&#8211; &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;-  &#8212;&#8212;&#8212;-<br />
total        8      0.01     215.04          0         11          0          28</p>
<p>Misses in library cache during parse: 2<br />
Optimizer goal: CHOOSE<br />
Parsing user id: 21</p>
<p>Rows     Row Source Operation<br />
&#8212;&#8212;-  &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
     14  VIEW<br />
     14   WINDOW SORT<br />
     14    TABLE ACCESS FULL T</p>
<p>********************************************************************************</p>
<p>I seems to me that the in-line view wins hands down!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alex Nuijten</title>
		<link>http://technology.amis.nl/2005/09/22/sqlplus-or-report-style-break-groups-in-sql-query/#comment-2445</link>
		<dc:creator>Alex Nuijten</dc:creator>
		<pubDate>Fri, 23 Sep 2005 07:53:09 +0000</pubDate>
		<guid isPermaLink="false">/?p=805#comment-2445</guid>
		<description><![CDATA[Nice! Analytical functions are soooo cool!

You can also omit the in-line view and use the row_number() in the case-statement:
&lt;pre&gt;
SQL&gt; explain plan for
  2  select ename
  3       , case Row_Number() over (partition by deptno
  4                                order by null
  5                            )
  6         when 1
  7         then deptno
  8         end
  9    from t
 10  /

Explained.

SQL&gt; @xplan

PLAN_TABLE_OUTPUT
--------------------------------------------------------------------
--------------------------------------------------------------------
&#124; Id  &#124; Operation            &#124;  Name       &#124; Rows  &#124; Bytes &#124; Cost  &#124;
--------------------------------------------------------------------
&#124;   0 &#124; SELECT STATEMENT     &#124;             &#124;    14 &#124;   126 &#124;     4 &#124;
&#124;   1 &#124;  WINDOW SORT         &#124;             &#124;    14 &#124;   126 &#124;     4 &#124;
&#124;   2 &#124;   TABLE ACCESS FULL  &#124; T           &#124;    14 &#124;   126 &#124;     1 &#124;
--------------------------------------------------------------------

Note: cpu costing is off

&lt;/pre&gt;

Notice the Bytes, when compared to using an in-line view:
&lt;pre&gt;
SQL&gt; explain plan for
  2  select ename
  3  ,      case rn
  4         when 1
  5         then deptno
  6         end  deptno
  7  from   ( select ename
  8           ,      deptno
  9           ,      row_number() over (partition by deptno order by null) rn
 10           from   t
 11         )
 12  /

Explained.

SQL&gt; @xplan

PLAN_TABLE_OUTPUT
--------------------------------------------------------------------
--------------------------------------------------------------------
&#124; Id  &#124; Operation            &#124;  Name       &#124; Rows  &#124; Bytes &#124; Cost  &#124;
--------------------------------------------------------------------
&#124;   0 &#124; SELECT STATEMENT     &#124;             &#124;    14 &#124;   462 &#124;     4 &#124;
&#124;   1 &#124;  VIEW                &#124;             &#124;    14 &#124;   462 &#124;     4 &#124;
&#124;   2 &#124;   WINDOW SORT        &#124;             &#124;    14 &#124;   126 &#124;     4 &#124;
&#124;   3 &#124;    TABLE ACCESS FULL &#124; T           &#124;    14 &#124;   126 &#124;     1 &#124;
--------------------------------------------------------------------

Note: cpu costing is off
&lt;/pre&gt;

(I run these scripts on a Oracle 9205, in case you&#039;re interested)]]></description>
		<content:encoded><![CDATA[<p>Nice! Analytical functions are soooo cool!</p>
<p>You can also omit the in-line view and use the row_number() in the case-statement:</p>
<pre class="wp-code-highlight prettyprint">
SQL&gt; explain plan for
  2  select ename
  3       , case Row_Number() over (partition by deptno
  4                                order by null
  5                            )
  6         when 1
  7         then deptno
  8         end
  9    from t
 10  /

Explained.

SQL&gt; @xplan

PLAN_TABLE_OUTPUT
--------------------------------------------------------------------
--------------------------------------------------------------------
| Id  | Operation            |  Name       | Rows  | Bytes | Cost  |
--------------------------------------------------------------------
|   0 | SELECT STATEMENT     |             |    14 |   126 |     4 |
|   1 |  WINDOW SORT         |             |    14 |   126 |     4 |
|   2 |   TABLE ACCESS FULL  | T           |    14 |   126 |     1 |
--------------------------------------------------------------------

Note: cpu costing is off

</pre>
<p>Notice the Bytes, when compared to using an in-line view:</p>
<pre class="wp-code-highlight prettyprint">
SQL&gt; explain plan for
  2  select ename
  3  ,      case rn
  4         when 1
  5         then deptno
  6         end  deptno
  7  from   ( select ename
  8           ,      deptno
  9           ,      row_number() over (partition by deptno order by null) rn
 10           from   t
 11         )
 12  /

Explained.

SQL&gt; @xplan

PLAN_TABLE_OUTPUT
--------------------------------------------------------------------
--------------------------------------------------------------------
| Id  | Operation            |  Name       | Rows  | Bytes | Cost  |
--------------------------------------------------------------------
|   0 | SELECT STATEMENT     |             |    14 |   462 |     4 |
|   1 |  VIEW                |             |    14 |   462 |     4 |
|   2 |   WINDOW SORT        |             |    14 |   126 |     4 |
|   3 |    TABLE ACCESS FULL | T           |    14 |   126 |     1 |
--------------------------------------------------------------------

Note: cpu costing is off
</pre>
<p>(I run these scripts on a Oracle 9205, in case you&#8217;re interested)</p>
]]></content:encoded>
	</item>
</channel>
</rss>
