<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Sokrates on Oracle</title>
	<atom:link href="http://marogel.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://marogel.wordpress.com</link>
	<description></description>
	<lastBuildDate>Wed, 22 May 2013 20:09:25 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='marogel.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Sokrates on Oracle</title>
		<link>http://marogel.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://marogel.wordpress.com/osd.xml" title="Sokrates on Oracle" />
	<atom:link rel='hub' href='http://marogel.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Partition Info in V$SESSION_LONGOPS</title>
		<link>http://marogel.wordpress.com/2013/05/10/partition-info-in-vsession_longops/</link>
		<comments>http://marogel.wordpress.com/2013/05/10/partition-info-in-vsession_longops/#comments</comments>
		<pubDate>Fri, 10 May 2013 13:51:52 +0000</pubDate>
		<dc:creator>Matthias Rogel</dc:creator>
				<category><![CDATA[Allgemein]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://marogel.wordpress.com/?p=354</guid>
		<description><![CDATA[Oracle&#8217;s advanced partitioning has some deficiencies. For example, partition info is missing in V$SESSION_LONGOPS for scan-operations ( full table scans, full index scans ). V$SESSION_LONGOPS.TARGET only shows OWNER.TABLE_NAME in these cases, even when the underlying table/index is partitioned, though the longop doesn&#8217;t refer to the whole segment but only to one (sub-)partition of it. I [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=marogel.wordpress.com&#038;blog=21611786&#038;post=354&#038;subd=marogel&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>Oracle&#8217;s advanced partitioning has some deficiencies. For example, partition info is missing in V$SESSION_LONGOPS for scan-operations ( full table scans, full index scans ). V$SESSION_LONGOPS.TARGET only shows <em>OWNER.TABLE_NAME</em> in these cases, even when the underlying table/index is partitioned, though the longop doesn&#8217;t refer to the whole segment but only to one (sub-)partition of it.<br />
I filed an enhancement request several years ago concerning this matter, but never received any feedback.<br />
However, there is a workaround to that. In many cases, we can find out on which (sub-) partition the longop is working on: V$SESSION_WAIT&#8217;s P1- and P2-info can be used for that in case the session is waiting mainly on I/O ( which might be most likely for many systems. )<br />
Here is an extension to V$SESSION_LONGOPS which tries to figure out this additional info:</p>
<pre class="brush: plain; title: ; notranslate">
select
   coalesce(
        (
            select 'does not apply'
            from dual
            where slo.TARGET not like '%.%'
            or slo.TARGET is null
        ),
        (
            select 'does not apply'
            from dba_tables dt
            where dt.OWNER=substr(slo.target, 1, instr(slo.target, '.') - 1)
            and dt.TABLE_NAME=substr(slo.target, instr(slo.target, '.') + 1)
            and dt.PARTITIONED='NO'        
        ),
        (
            select 
               de.partition_name || ' (' || de.segment_type || ')'
            from v$session_wait sw, dba_extents de
            where
              sw.sid=slo.sid
            and slo.opname like '%Scan%'
            and sw.P1TEXT like 'file%'
            and sw.P1 = de.FILE_ID and sw.P2 between de.BLOCK_ID and de.BLOCK_ID + de.BLOCKS - 1
            and de.owner = substr(slo.target, 1, instr(slo.target, '.') - 1)
            and de.segment_type in 
            (
               'TABLE PARTITION', 'TABLE SUBPARTITION',
               'INDEX PARTITION', 'INDEX SUBPARTITION'             
            )
            and de.segment_name in 
            (
                 -- table
                 select 
                    substr(slo.target, instr(slo.target, '.') + 1)
                 from dual
                 union all
                 -- index
                 select di.index_name
                 from dba_indexes di
                 where di.owner=substr(slo.target, 1, instr(slo.target, '.') - 1)
                 and di.TABLE_NAME = substr(slo.target, instr(slo.target, '.') + 1)
            )
         ),
        'unknown'
      )
   as partition_info,     
   slo.*
from v$session_longops slo
where slo.TIME_REMAINING &gt; 0
</pre>
<p>Note that this might take a bit longer than a simple</p>
<pre class="brush: plain; title: ; notranslate">
select slo.*
from v$session_longops slo
where slo.TIME_REMAINING &gt; 0
</pre>
<p>, though due to coalesce&#8217;s short circuiting it is quite efficient.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/marogel.wordpress.com/354/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/marogel.wordpress.com/354/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=marogel.wordpress.com&#038;blog=21611786&#038;post=354&#038;subd=marogel&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://marogel.wordpress.com/2013/05/10/partition-info-in-vsession_longops/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/fe4e3c9c551b4c60e25179b489fc11dd?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">marogel</media:title>
		</media:content>
	</item>
		<item>
		<title>(UTL_RAW.)CAST_TO_DATE</title>
		<link>http://marogel.wordpress.com/2013/04/29/utl_raw-cast_to_date/</link>
		<comments>http://marogel.wordpress.com/2013/04/29/utl_raw-cast_to_date/#comments</comments>
		<pubDate>Mon, 29 Apr 2013 14:00:45 +0000</pubDate>
		<dc:creator>Matthias Rogel</dc:creator>
				<category><![CDATA[Allgemein]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://marogel.wordpress.com/?p=346</guid>
		<description><![CDATA[Tim wrote &#8230; the UTL_RAW package has a bunch of casting functions for RAW values (CAST_TO_BINARY_DOUBLE, CAST_TO_BINARY_FLOAT, CAST_TO_BINARY_INTEGER, CAST_TO_NUMBER, CAST_TO_NVARCHAR2, CAST_TO_VARCHAR2). Note the absence of a CAST_TO_DATE function. Bertrand Drouvot also misses it, see Bind variable peeking: Retrieve peeked and passed values per execution in oracle 11.2 Here is a try to write one, fixes [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=marogel.wordpress.com&#038;blog=21611786&#038;post=346&#038;subd=marogel&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p><a href="http://jonathanlewis.wordpress.com/2006/11/29/low_value-high_value/#comment-318" title="Tim wrote" target="_blank">Tim wrote</a><br />
<em>&#8230; the  UTL_RAW package has a bunch of casting functions for RAW values (CAST_TO_BINARY_DOUBLE, CAST_TO_BINARY_FLOAT, CAST_TO_BINARY_INTEGER, CAST_TO_NUMBER, CAST_TO_NVARCHAR2, CAST_TO_VARCHAR2). Note the absence of a CAST_TO_DATE function.</em></p>
<p>Bertrand Drouvot also misses it, see <a href="http://bdrouvot.wordpress.com/2013/04/29/bind-variable-peeking-retrieve-peeked-and-passed-values-per-execution-in-oracle-11-2/" title="Bind variable peeking: Retrieve peeked and passed values per execution in oracle 11.2" target="_blank">Bind variable peeking: Retrieve peeked and passed values per execution in oracle 11.2</a></p>
<p>Here is a try to write one, fixes and improvements are welcome !</p>
<pre class="brush: plain; title: ; notranslate">
create or replace function CAST_TO_DATE(bdr in raw) return date deterministic is
begin
  return
     date'1-1-1'
     + NUMTOYMINTERVAL(
         100 * (to_number(substr(bdr,1,2), 'xx') - 100) + 
         to_number(substr(bdr,3,2), 'xx') - 101, 
       'year')
     + NUMTOYMINTERVAL(to_number(substr(bdr,5,2), 'xx')-1, 'month')
     + NUMTODSINTERVAL(to_number(substr(bdr,7,2), 'xx')-1, 'day')
     + NUMTODSINTERVAL(to_number(substr(bdr,9,2), 'xx') - 1, 'hour')   
     + NUMTODSINTERVAL(to_number(substr(bdr,11,2), 'xx') - 1, 'minute')   
     + NUMTODSINTERVAL(to_number(substr(bdr,13,2), 'xx') - 1, 'second');
  exception when others then return to_date(1, 'J');
end CAST_TO_DATE;   
/
</pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/marogel.wordpress.com/346/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/marogel.wordpress.com/346/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=marogel.wordpress.com&#038;blog=21611786&#038;post=346&#038;subd=marogel&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://marogel.wordpress.com/2013/04/29/utl_raw-cast_to_date/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/fe4e3c9c551b4c60e25179b489fc11dd?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">marogel</media:title>
		</media:content>
	</item>
		<item>
		<title>A simple pipelined version of print_table</title>
		<link>http://marogel.wordpress.com/2013/04/10/a-simple-pipelined-version-of-print_table/</link>
		<comments>http://marogel.wordpress.com/2013/04/10/a-simple-pipelined-version-of-print_table/#comments</comments>
		<pubDate>Wed, 10 Apr 2013 10:36:44 +0000</pubDate>
		<dc:creator>Matthias Rogel</dc:creator>
				<category><![CDATA[Allgemein]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://marogel.wordpress.com/?p=334</guid>
		<description><![CDATA[Tom Kyte&#8217;s print_table procedure, available on http://asktom.oracle.com/pls/apex/f?p=100:11:0::::P11_QUESTION_ID:1035431863958#14442395195806 seems to be very popular and there exist tricky variations on the theme, for example the following nice xml-trick by Sayan Malakshinov. Please note that it is very easy to use the existing print_table-code to generate a pipelined version which can be used in SQL. I use the [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=marogel.wordpress.com&#038;blog=21611786&#038;post=334&#038;subd=marogel&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>Tom Kyte&#8217;s print_table procedure, available on<br />
<a href="http://asktom.oracle.com/pls/apex/f?p=100:11:0::::P11_QUESTION_ID:1035431863958#14442395195806" target="_blank">http://asktom.oracle.com/pls/apex/f?p=100:11:0::::P11_QUESTION_ID:1035431863958#14442395195806</a><br />
seems to be very popular and there exist tricky variations on the theme, for example the following <a href="http://orasql.org/2013/04/02/sqlplus-tips-2/" title="nice xml-trick by Sayan Malakshinov" target="_blank">nice xml-trick by Sayan Malakshinov</a>.</p>
<p>Please note that it is very easy to use the existing print_table-code to generate a pipelined version which can be used in SQL.<br />
I use the following code since ages and it always does me a great job, so probably it is worth sharing.</p>
<pre class="brush: plain; title: ; notranslate">
create or replace function fprint_table
( p_query in varchar2,
  p_date_fmt in varchar2 default 'dd-mon-yyyy hh24:mi:ss' )
return sys.odcivarchar2list 
authid current_user
pipelined
   is
l varchar2(4000);
s integer default 1;
begin
  dbms_output.enable(buffer_size =&gt; null);
  
  print_table(
     p_query =&gt; p_query,
     p_date_fmt =&gt; p_date_fmt
  );

  loop
     dbms_output.get_line(line =&gt; l, status =&gt; s);
     exit when s != 0;
     begin
        pipe row(l);
     exception when no_data_needed then exit;
     end;
  end loop;
    
  return;

end fprint_table;
/

sokrates@11.2 &gt; select * from table(fprint_table('select user,sysdate from dual'));

USER                          : SOKRATES
SYSDATE                       : 10-apr-2013 12:27:50
-----------------
1 row selected.
</pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/marogel.wordpress.com/334/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/marogel.wordpress.com/334/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=marogel.wordpress.com&#038;blog=21611786&#038;post=334&#038;subd=marogel&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://marogel.wordpress.com/2013/04/10/a-simple-pipelined-version-of-print_table/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/fe4e3c9c551b4c60e25179b489fc11dd?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">marogel</media:title>
		</media:content>
	</item>
		<item>
		<title>An undocumented restriction in Workspace Manager &#8211; exporting tables with valid time support</title>
		<link>http://marogel.wordpress.com/2013/02/07/an-undocumented-restriction-in-workspace-manager-exporting-tables-with-valid-time-support/</link>
		<comments>http://marogel.wordpress.com/2013/02/07/an-undocumented-restriction-in-workspace-manager-exporting-tables-with-valid-time-support/#comments</comments>
		<pubDate>Thu, 07 Feb 2013 16:13:37 +0000</pubDate>
		<dc:creator>Matthias Rogel</dc:creator>
				<category><![CDATA[Allgemein]]></category>
		<category><![CDATA[11.2]]></category>
		<category><![CDATA[features]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://marogel.wordpress.com/?p=326</guid>
		<description><![CDATA[If you are using Workspace Manager, it could be probably useful to know, that there is an undocumented restriction concerning import/export. Due to Import and Export Considerations, &#8230;Workspace Manager supports the import and export of version-enabled tables in one of the following two ways: a full database import and export, and a workspace-level import and [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=marogel.wordpress.com&#038;blog=21611786&#038;post=326&#038;subd=marogel&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>If you are using <a href="http://docs.oracle.com/cd/E11882_01/appdev.112/e11826/toc.htm" target="_blank">Workspace Manager</a>, it could be probably useful to know, that there is an undocumented restriction concerning import/export.<br />
Due to <a href="http://docs.oracle.com/cd/E11882_01/appdev.112/e11826/long_intro.htm#i1018057" target="_blank">Import and Export Considerations</a>,<br />
<em>&#8230;Workspace Manager supports the import and export of version-enabled tables in one of the following two ways: a full database import and export, and a workspace-level import and export through Workspace Manager procedures. No other export modes, such as schema, table, or partition level, are currently supported&#8230;.</em></p>
<p>However, this does not hold for <a href="http://docs.oracle.com/cd/E11882_01/appdev.112/e11826/long_vt.htm#ADWSM035" target="_blank">tables with valid time support</a>:</p>
<pre class="brush: plain; title: ; notranslate">
sokrates@11.2 &gt; CREATE TABLE d (id NUMBER PRIMARY KEY);

Table created.

sokrates@11.2 &gt; EXECUTE DBMS_WM.EnableVersioning (table_name=&gt;'D', validTime=&gt;TRUE, hist =&gt; 'NONE');

PL/SQL procedure successfully completed.

sokrates@11.2 &gt;  EXECUTE DBMS_WM.Export(table_name =&gt; 'D',staging_table =&gt; 'D_STG', workspace =&gt; 'LIVE');
BEGIN DBMS_WM.Export(table_name =&gt; 'D',staging_table =&gt; 'D_STG', workspace =&gt; 'LIVE'); END;

*
ERROR at line 1:
ORA-20171: WM error: Export not supported on a table with valid time
ORA-06512: at &quot;WMSYS.LT&quot;, line 13185
ORA-06512: at line 1
</pre>
<p>Support confirmed, that in this case <strong>only full db import/export</strong> (!) is supported, documentation would be updated somewhen.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/marogel.wordpress.com/326/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/marogel.wordpress.com/326/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=marogel.wordpress.com&#038;blog=21611786&#038;post=326&#038;subd=marogel&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://marogel.wordpress.com/2013/02/07/an-undocumented-restriction-in-workspace-manager-exporting-tables-with-valid-time-support/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/fe4e3c9c551b4c60e25179b489fc11dd?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">marogel</media:title>
		</media:content>
	</item>
		<item>
		<title>tuning</title>
		<link>http://marogel.wordpress.com/2013/02/04/tuning/</link>
		<comments>http://marogel.wordpress.com/2013/02/04/tuning/#comments</comments>
		<pubDate>Mon, 04 Feb 2013 21:14:24 +0000</pubDate>
		<dc:creator>Matthias Rogel</dc:creator>
				<category><![CDATA[Allgemein]]></category>

		<guid isPermaLink="false">http://marogel.wordpress.com/?p=323</guid>
		<description><![CDATA[The biggest advantage of being developer and DBA at the same time in my eyes is: tuning lies in one hand. Peter Scott twittered about bringing a query down from 25 hours to 83 seconds by rewriting a query using MINUS. Funny, in February 1996 I started a new job and my first task was [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=marogel.wordpress.com&#038;blog=21611786&#038;post=323&#038;subd=marogel&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>The biggest advantage of being developer and DBA at the same time in my eyes is: tuning lies in one hand.<br />
<a href="https://twitter.com/dw_pete/status/298089636088147968" title="Peter Scott twittered " target="_blank">Peter Scott twittered about bringing a query down from 25 hours to 83 seconds</a> by rewriting a query using MINUS.<br />
Funny, in February 1996 I started a new job and my first task was tuning a query running for several hours &#8211; basically</p>
<pre class="brush: plain; title: ; notranslate">
select ...
from t
where not exists
( select ...
  from r@remote r
  where &lt;join t and r&gt;
)
</pre>
<p>which could be tuned down to a few seconds using MINUS, so quite similar to Peter&#8217;s job ( Version was 7.0.something at that time as far as I remember ).<br />
In my experience, most performance gains are achieved by rewriting SQL or even by restructuring your entire application logic.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/marogel.wordpress.com/323/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/marogel.wordpress.com/323/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=marogel.wordpress.com&#038;blog=21611786&#038;post=323&#038;subd=marogel&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://marogel.wordpress.com/2013/02/04/tuning/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/fe4e3c9c551b4c60e25179b489fc11dd?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">marogel</media:title>
		</media:content>
	</item>
		<item>
		<title>what&#8217;s in my buffer cache ?</title>
		<link>http://marogel.wordpress.com/2013/02/04/whats-in-my-buffer-cache/</link>
		<comments>http://marogel.wordpress.com/2013/02/04/whats-in-my-buffer-cache/#comments</comments>
		<pubDate>Mon, 04 Feb 2013 20:47:54 +0000</pubDate>
		<dc:creator>Matthias Rogel</dc:creator>
				<category><![CDATA[Allgemein]]></category>
		<category><![CDATA[dba sql]]></category>

		<guid isPermaLink="false">http://marogel.wordpress.com/?p=319</guid>
		<description><![CDATA[The following SQL shows me what is currently in my buffer cache and runs in a reasonable amount of time ( never longer than 30 seconds with some dozens of GB buffer cache and around 5 million entries in v$cache ), it also shows me the cached percentage of each segment which is currently part [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=marogel.wordpress.com&#038;blog=21611786&#038;post=319&#038;subd=marogel&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>The following SQL shows me what is currently in my buffer cache and runs in a reasonable amount of time ( never longer than 30 seconds with some dozens of GB buffer cache and around 5 million entries in v$cache ), it also shows me the cached percentage of each segment which is currently part of the cache.<br />
Version is 11.2.</p>
<pre class="brush: plain; title: ; notranslate">
with cache_raw 
as 
(
  select
     c.owner#, c.kind, c.name, c.partition_name, 
     c.status, c.file#, 
     count(*) co
  from v$cache c
  group by 
     c.owner#, c.kind, c.name, c.partition_name,
     c.partition_name, file#, c.status
), cache_raw2
as
(
  select 
     du.username, c.kind, 
     case when c.partition_name is null
            then c.name
            else c.name || ' partition ' || c.partition_name
     end as name,
     case c.status
        when 'free' then 'not currently in use'
        when 'xcur' then 'exclusive'
        when 'scur' then 'shared current'
        when 'cr' then 'consistent read'
        when 'read' then 'being read from disk'
        when 'mrec' then 'in media recovery mode'
        when 'irec' then 'in instance recovery mode'
     end as status,
     c.file#,  
     co * (select value from v$parameter where name='db_block_size') as anzb
  from cache_raw c, dba_users du
  where du.user_id(+)=c.owner#
), cache_segm as
(
  select 
     c.username as owner, c.kind, 
     case 
       when c.kind in ('INDEX', 'INDEX PARTITION')
       then c.name || ' index on '|| ind.table_name
       else c.name
     end as name, 
     round(100 * c.anzb / sum(c.anzb) over (), 2) percentage,
     round(c.anzb / (1024 * 1024 * 1024), 2) as gbytes_in_cache, 
     round(100 * c.anzb / seg.bytes, 2) perc_of_segment_in_cache, 
     round(seg.bytes / (1024 * 1024 * 1024), 2) as gbytes_in_segment,   
     c.status, 
     round(c.anzb / (1024 * 1024), 2) as mbytes_in_cache,
     round(seg.bytes / (1024 * 1024), 2) as mbytes_in_segment,   
     round(c.anzb / (1024), 2) as kbytes_in_cache,   
     round(seg.bytes / (1024), 2) as kbytes_in_segment,            
     c.anzb as bytes_in_cache, 
     seg.bytes as bytes_in_segment,   
     seg.segment_subtype, seg.tablespace_name
  from cache_raw2 c, dba_segments seg, dba_indexes ind
  where 
     seg.owner(+)=c.username
     and 
     case when seg.partition_name(+) is null
            then seg.segment_name(+)
            else seg.segment_name(+) || ' partition ' || seg.partition_name(+)
     end = c.name
     and seg.segment_type(+)=c.kind
  and
     ind.owner(+)=c.username and ind.index_name(+)=nvl(substr(c.name, 1, instr(c.name, ' ', 1) - 1), c.name)
)   
  select 
     case row_number() over(order by c.bytes_in_cache desc) 
       when 1 then round(sum(c.bytes_in_cache) over () / (1024 * 1024 * 1024), 2) 
     end as gb_total,
     c.owner, c.kind, c.name, 
     c.percentage,
     c.gbytes_in_cache, c.perc_of_segment_in_cache, 
     c.gbytes_in_segment, c.status, 
     c.mbytes_in_cache, c.mbytes_in_segment,   
     c.kbytes_in_cache, c.kbytes_in_segment,            
     c.bytes_in_cache, c.bytes_in_segment,   
     c.segment_subtype, c.tablespace_name
  from cache_segm c
  order by 
     c.bytes_in_cache desc
</pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/marogel.wordpress.com/319/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/marogel.wordpress.com/319/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=marogel.wordpress.com&#038;blog=21611786&#038;post=319&#038;subd=marogel&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://marogel.wordpress.com/2013/02/04/whats-in-my-buffer-cache/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/fe4e3c9c551b4c60e25179b489fc11dd?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">marogel</media:title>
		</media:content>
	</item>
		<item>
		<title>Mount an xml-file as &#8220;External Table&#8221;</title>
		<link>http://marogel.wordpress.com/2013/01/03/mount-an-xml-file-as-external-table/</link>
		<comments>http://marogel.wordpress.com/2013/01/03/mount-an-xml-file-as-external-table/#comments</comments>
		<pubDate>Thu, 03 Jan 2013 16:52:20 +0000</pubDate>
		<dc:creator>Matthias Rogel</dc:creator>
				<category><![CDATA[Allgemein]]></category>
		<category><![CDATA[SQL XML]]></category>

		<guid isPermaLink="false">http://marogel.wordpress.com/?p=283</guid>
		<description><![CDATA[&#8220;Mounting&#8221; a csv-file as external-table is very handy. Here a quick note to show, that we can &#8220;mount&#8221; an xml-file as well ( and query it via SQL )  <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=marogel.wordpress.com&#038;blog=21611786&#038;post=283&#038;subd=marogel&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>&#8220;Mounting&#8221; a csv-file as external-table is very handy.</p>
<p>Here a quick note to show, that we can &#8220;mount&#8221; an xml-file as well ( and query it via SQL )</p>
<p> </p>
<pre class="brush: plain; title: ; notranslate">
sokrates@11.2 &gt; create directory t as '/tmp';
Directory created.
sokrates@11.2 &gt; !wget -O /tmp/t.xml www.w3schools.com/xml/simple.xml
--17:31:25-- http://www.w3schools.com/xml/simple.xml
Resolving www.w3schools.com... 66.29.212.73
Connecting to www.w3schools.com|66.29.212.73|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1135 (1.1K) [text/xml]
Saving to: `/tmp/t.xml'
100%[============================================================================================================================&gt;] 1,135 --.-K/s in 0s
17:31:25 (216 MB/s) - `/tmp/t.xml' saved [1135/1135]
sokrates@11.2 &gt; !cat /tmp/t.xml
&lt;?xml version=&quot;1.0&quot; encoding=&quot;ISO-8859-1&quot;?&gt;
&lt;!-- Edited by XMLSpy? --&gt;
&lt;breakfast_menu&gt;
 &lt;food&gt;
 &lt;name&gt;Belgian Waffles&lt;/name&gt;
 &lt;price&gt;$5.95&lt;/price&gt;
 &lt;description&gt;two of our famous Belgian Waffles with plenty of real maple syrup&lt;/description&gt;
 &lt;calories&gt;650&lt;/calories&gt;
 &lt;/food&gt;
 &lt;food&gt;
 &lt;name&gt;Strawberry Belgian Waffles&lt;/name&gt;
 &lt;price&gt;$7.95&lt;/price&gt;
 &lt;description&gt;light Belgian waffles covered with strawberries and whipped cream&lt;/description&gt;
 &lt;calories&gt;900&lt;/calories&gt;
 &lt;/food&gt;
 &lt;food&gt;
 &lt;name&gt;Berry-Berry Belgian Waffles&lt;/name&gt;
 &lt;price&gt;$8.95&lt;/price&gt;
 &lt;description&gt;light Belgian waffles covered with an assortment of fresh berries and whipped cream&lt;/description&gt;
 &lt;calories&gt;900&lt;/calories&gt;
 &lt;/food&gt;
 &lt;food&gt;
 &lt;name&gt;French Toast&lt;/name&gt;
 &lt;price&gt;$4.50&lt;/price&gt;
 &lt;description&gt;thick slices made from our homemade sourdough bread&lt;/description&gt;
 &lt;calories&gt;600&lt;/calories&gt;
 &lt;/food&gt;
 &lt;food&gt;
 &lt;name&gt;Homestyle Breakfast&lt;/name&gt;
 &lt;price&gt;$6.95&lt;/price&gt;
 &lt;description&gt;two eggs, bacon or sausage, toast, and our ever-popular hash browns&lt;/description&gt;
 &lt;calories&gt;950&lt;/calories&gt;
 &lt;/food&gt;
&lt;/breakfast_menu&gt;
sokrates@11.2 &gt; select
 2 x.*
 3 from XMLTable(
 4 '/breakfast_menu/food'
 5 passing
 6 xmltype(
 7 bfilename('T','t.xml'), nls_charset_id('WE8ISO8859P1')
 8 )
 9 columns
 10 name varchar2(50) path 'name',
 11 price varchar2(20) path 'price',
 12 description varchar2(200) path 'description',
 13 calories number path 'calories'
 14 ) x;
NAME PRICE DESCRIPTION CALORIES
------------------------------ ------- ------------------------------------------------------------------------------------------ ------------
Belgian Waffles $5.95 two of our famous Belgian Waffles with plenty of real maple syrup 650
Strawberry Belgian Waffles $7.95 light Belgian waffles covered with strawberries and whipped cream 900
Berry-Berry Belgian Waffles $8.95 light Belgian waffles covered with an assortment of fresh berries and whipped cream 900
French Toast $4.50 thick slices made from our homemade sourdough bread 600
Homestyle Breakfast $6.95 two eggs, bacon or sausage, toast, and our ever-popular hash 
</pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/marogel.wordpress.com/283/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/marogel.wordpress.com/283/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=marogel.wordpress.com&#038;blog=21611786&#038;post=283&#038;subd=marogel&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://marogel.wordpress.com/2013/01/03/mount-an-xml-file-as-external-table/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/fe4e3c9c551b4c60e25179b489fc11dd?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">marogel</media:title>
		</media:content>
	</item>
		<item>
		<title>ORA-54012 oddity and a workaround</title>
		<link>http://marogel.wordpress.com/2012/09/03/ora-54012-oddity-and-a-workaround/</link>
		<comments>http://marogel.wordpress.com/2012/09/03/ora-54012-oddity-and-a-workaround/#comments</comments>
		<pubDate>Mon, 03 Sep 2012 14:43:26 +0000</pubDate>
		<dc:creator>Matthias Rogel</dc:creator>
				<category><![CDATA[11.2]]></category>
		<category><![CDATA[Allgemein]]></category>
		<category><![CDATA[Bug]]></category>
		<category><![CDATA[bugfighting]]></category>

		<guid isPermaLink="false">http://marogel.wordpress.com/?p=279</guid>
		<description><![CDATA[<blockquote>qwdqwd</blockquote><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=marogel.wordpress.com&#038;blog=21611786&#038;post=279&#038;subd=marogel&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<pre class="brush: sql; highlight: [7];">sokrates@11.2 &gt; create package p is
2 function func return int deterministic;
3 end p;
4 /

Package created.

sokrates@11.2 &gt; create table t(
2 i int,
3 func as ( p.func() )
4 );
func as ( p.func() )
*
ERROR at line 3:
ORA-54012: virtual column is referenced in a column expression</pre>
<p>oops ? what&#8217;s wrong ?</p>
<p><a href="http://docs.oracle.com/cd/E11882_01/server.112/e17766/e53000.htm#sthref13803" rel="nofollow">http://docs.oracle.com/cd/E11882_01/server.112/e17766/e53000.htm#sthref13803</a></p>
<p>says</p>
<figure class="quote">
<blockquote>
<p>ORA-54012: virtual column is referenced in a column expression<br />
Cause: This virtual column was referenced in an expression of another virtual column</p>
</blockquote>
</figure>
<p>which is not true: there is no &#8220;another virtual column&#8221;, there is only one virtual column.<br />
It seems, I cannot name a virtual column the same as its generating function &#8211; at least in a &#8220;create table&#8221;, we have to split this &#8220;create table&#8221; in a &#8220;create table&#8221; and an &#8220;alter table&#8221;.</p>
<p>So</p>
<pre class="brush: sql; highlight: [7];">sokrates@11.2 &gt; create table t(
2 i int,
3 fun as ( p.func() )
4 );

Table created.

sokrates@11.2 &gt; alter table t rename column fun to func;

Table altered.</pre>
<p>So we end up in a table for which the SQL generated by dbms_metadata cannot be replayed, see:</p>
<pre class="brush: sql; highlight: [7];">sokrates@11.2 &gt; select dbms_metadata.get_ddl('TABLE', 'T') from dual;

DBMS_METADATA.GET_DDL('TABLE','T')
--------------------------------------------------------------------------------

  CREATE TABLE "SOKRATES"."T"
   (    "I" NUMBER(*,0),
        "FUNC" NUMBER GENERATED ALWAYS AS ("SOKRATES"."P"."FUNC"()) VIRTUAL VISIBLE
   ) SEGMENT CREATION DEFERRED
  PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
  TABLESPACE "USERS"

sokrates@11.2 &gt; drop table t purge;

Table dropped.

sokrates@11.2 &gt; REM copy &amp; and paste the above DBMS_METADATA - output
sokrates@11.2 &gt; CREATE TABLE "SOKRATES"."T"
  2   (    "I" NUMBER(*,0),
  3        "FUNC" NUMBER GENERATED ALWAYS AS ("SOKRATES"."P"."FUNC"()) VIRTUAL VISIBLE
  4   ) SEGMENT CREATION DEFERRED
  5  PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
  6  TABLESPACE "USERS";
      "FUNC" NUMBER GENERATED ALWAYS AS ("SOKRATES"."P"."FUNC"()) VIRTUAL VISIBLE
      *
ERROR at line 3:
ORA-54012: virtual column is referenced in a column expression</pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/marogel.wordpress.com/279/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/marogel.wordpress.com/279/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=marogel.wordpress.com&#038;blog=21611786&#038;post=279&#038;subd=marogel&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://marogel.wordpress.com/2012/09/03/ora-54012-oddity-and-a-workaround/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/fe4e3c9c551b4c60e25179b489fc11dd?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">marogel</media:title>
		</media:content>
	</item>
		<item>
		<title>select the scale of a number</title>
		<link>http://marogel.wordpress.com/2012/08/10/select-the-scale-of-a-number-2/</link>
		<comments>http://marogel.wordpress.com/2012/08/10/select-the-scale-of-a-number-2/#comments</comments>
		<pubDate>Fri, 10 Aug 2012 11:45:17 +0000</pubDate>
		<dc:creator>Matthias Rogel</dc:creator>
				<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://marogel.wordpress.com/?p=276</guid>
		<description><![CDATA[<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=marogel.wordpress.com&#038;blog=21611786&#038;post=276&#038;subd=marogel&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<pre class="brush: plain; title: ; notranslate">with qs as
(
select
round(
dbms_random.value(-20, 20),
dbms_random.value(1, 15)
) q
from dual
connect by level&lt;=10
)
select
qs.q,
case
when qs.q = floor(qs.q) then
0
when qs.q is null then null
else
(
select max(level)
from dual
connect by round(qs.q, level - 1) != qs.q
)
end as &quot;scale(q)&quot;
from qs</pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/marogel.wordpress.com/276/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/marogel.wordpress.com/276/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=marogel.wordpress.com&#038;blog=21611786&#038;post=276&#038;subd=marogel&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://marogel.wordpress.com/2012/08/10/select-the-scale-of-a-number-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/fe4e3c9c551b4c60e25179b489fc11dd?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">marogel</media:title>
		</media:content>
	</item>
		<item>
		<title>Learning foreign languages with Oracle SQL</title>
		<link>http://marogel.wordpress.com/2012/03/23/learning-foreign-languages-with-oracle-sql/</link>
		<comments>http://marogel.wordpress.com/2012/03/23/learning-foreign-languages-with-oracle-sql/#comments</comments>
		<pubDate>Fri, 23 Mar 2012 13:02:36 +0000</pubDate>
		<dc:creator>Matthias Rogel</dc:creator>
				<category><![CDATA[Allgemein]]></category>
		<category><![CDATA[fun]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://marogel.wordpress.com/2012/03/23/learning-foreign-languages-with-oracle-sql/</guid>
		<description><![CDATA[TRADITIONAL CHINESE looks easy<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=marogel.wordpress.com&#038;blog=21611786&#038;post=267&#038;subd=marogel&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<pre class="brush: plain; title: ; notranslate">with y as
(
   select 
      add_months(date'2012-01-01', level-1) monn, 
      to_char(add_months(date'2012-01-01', level-1), 'MONTH') mon
   from dual
   connect by level&lt;=12
)
select 
   value as language, 
   y.mon, 
   to_char(y.monn, 'MONTH', q'|nls_date_language='|' || value || q'|'|') month, 
   to_char(y.monn, 'MON', q'|nls_date_language='|' || value || q'|'|') month_s
from v$nls_valid_values n, y
where n.parameter='LANGUAGE'
order by language, y.monn</pre>
<p>TRADITIONAL CHINESE looks easy</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/marogel.wordpress.com/267/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/marogel.wordpress.com/267/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=marogel.wordpress.com&#038;blog=21611786&#038;post=267&#038;subd=marogel&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://marogel.wordpress.com/2012/03/23/learning-foreign-languages-with-oracle-sql/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/fe4e3c9c551b4c60e25179b489fc11dd?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">marogel</media:title>
		</media:content>
	</item>
	</channel>
</rss>
