<?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"
	>

<channel>
	<title>Oracle Expert</title>
	<atom:link href="http://www.oracleexpert.co.uk/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.oracleexpert.co.uk</link>
	<description>Hilda Davies, an Oracle Data Architect, based in London, UK.</description>
	<pubDate>Wed, 11 Jan 2012 14:42:13 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.3</generator>
	<language>en</language>
			<item>
		<title>Oracle Space Management - Segment Advisor</title>
		<link>http://www.oracleexpert.co.uk/2012/01/oracle-space-management-segment-advisor/</link>
		<comments>http://www.oracleexpert.co.uk/2012/01/oracle-space-management-segment-advisor/#comments</comments>
		<pubDate>Wed, 04 Jan 2012 15:43:24 +0000</pubDate>
		<dc:creator>Hilda</dc:creator>
		
		<category><![CDATA[General]]></category>

		<category><![CDATA[Sandbox]]></category>

		<category><![CDATA[fragmentation]]></category>

		<category><![CDATA[segment advisor]]></category>

		<guid isPermaLink="false">http://www.oracleexpert.co.uk/?p=435</guid>
		<description><![CDATA[Here is a very useful query to highlight which tables/indexes would benefit from a reorg/rebuild or a shrink
SELECT segment_name, segment_type, round(allocated_space/1024/1024,3) alloc_mb ,round(used_space/1024/1024,3) used_mb ,
round(reclaimable_space/1024/1024,3) reclaimable_mb, round(reclaimable_space/allocated_space*100,3) pct_wastage
FROM TABLE(dbms_space.asa_recommendations())
where segment_owner=&#8217;HILDA&#8217;
order by 6 desc
]]></description>
			<content:encoded><![CDATA[<p>Here is a very useful query to highlight which tables/indexes would benefit from a reorg/rebuild or a shrink</p>
<p>SELECT segment_name, segment_type, round(allocated_space/1024/1024,3) alloc_mb ,round(used_space/1024/1024,3) used_mb ,<br />
round(reclaimable_space/1024/1024,3) reclaimable_mb, round(reclaimable_space/allocated_space*100,3) pct_wastage<br />
FROM TABLE(dbms_space.asa_recommendations())<br />
where segment_owner=&#8217;HILDA&#8217;<br />
order by 6 desc</p>
]]></content:encoded>
			<wfw:commentRss>http://www.oracleexpert.co.uk/2012/01/oracle-space-management-segment-advisor/feed/</wfw:commentRss>
		</item>
		<item>
		<title>ash</title>
		<link>http://www.oracleexpert.co.uk/2012/01/ash/</link>
		<comments>http://www.oracleexpert.co.uk/2012/01/ash/#comments</comments>
		<pubDate>Wed, 04 Jan 2012 09:42:25 +0000</pubDate>
		<dc:creator>Hilda</dc:creator>
		
		<category><![CDATA[Sandbox]]></category>

		<category><![CDATA[ash]]></category>

		<guid isPermaLink="false">http://www.oracleexpert.co.uk/?p=430</guid>
		<description><![CDATA[Reminder for me on how useful ASH is
&#8211; find snapid where a particular sql occurs
select distinct snap_id from dba_hist_sqlbind where sql_id=&#8217;80bd6bb7n33tk&#8217;  
&#8211; find bind variable values for the specified sql
select * from dba_hist_sqlbind
where snap_id = 20637  and trunc(last_captured) >= &#8216;17-NOV-2011&#8242; and sql_id=&#8217;80bd6bb7n33tk&#8217;
order by sql_id, position
select snap_id, sample_time, session_id, session_serial#, sql_id, session_state, blocking_session, blocking_session_serial#, [...]]]></description>
			<content:encoded><![CDATA[<p>Reminder for me on how useful ASH is</p>
<p>&#8211; find snapid where a particular sql occurs<br />
select distinct snap_id from dba_hist_sqlbind where sql_id=&#8217;80bd6bb7n33tk&#8217;  </p>
<p>&#8211; find bind variable values for the specified sql<br />
select * from dba_hist_sqlbind<br />
where snap_id = 20637  and trunc(last_captured) >= &#8216;17-NOV-2011&#8242; and sql_id=&#8217;80bd6bb7n33tk&#8217;<br />
order by sql_id, position</p>
<p>select snap_id, sample_time, session_id, session_serial#, sql_id, session_state, blocking_session, blocking_session_serial#, blocking_session_status, event from dba_hist_active_sess_history<br />
where (session_id,session_serial#) in (select session_id,session_serial# from dba_hist_active_sess_history where sql_id=&#8217;0trpbjywfsdp6&#8242; and snap_id between 20637 and 20639)<br />
and snap_id between 20637 and 20639 order by snap_id, sample_time</p>
<p>4a2fkw1d4u01u &#8212; deletion profile that was blocked </p>
<p>select snap_id, sample_time, session_id, session_serial#, sql_id, session_state, blocking_session, blocking_session_serial#, blocking_session_status, event from dba_hist_active_sess_history<br />
where (session_id,session_serial#) in (select session_id,session_serial# from dba_hist_active_sess_history where sql_id=&#8217;4a2fkw1d4u01u&#8217; and snap_id between 20637 and 20639)<br />
and snap_id between 20637 and 20639 order by snap_id, sample_time</p>
<p>select &#8216;USER&#8217;, sample_time, sql_id, session_state, blocking_session, blocking_session_serial#, blocking_session_status, event,<br />
(select sql_text from v$sql where sql_id=a.sql_id and rownum=1) xxx from dba_hist_active_sess_history  a<br />
where session_id=762 and session_serial#=45940<br />
and snap_id between 20637 and 20642 order by snap_id, sample_time</p>
<p>&#8211; blocked ETL Session<br />
select &#8216;ETL&#8217;, sample_time, sql_id, session_state, blocking_session, blocking_session_serial#, blocking_session_status, event,<br />
(select sql_text from DBA_HIST_SQLtext where sql_id=a.sql_id and rownum=1) xxx from dba_hist_active_sess_history  a<br />
where session_id=829 and session_serial#=31419<br />
and snap_id between 20637 and 20642 order by snap_id, sample_time</p>
<p>&#8211;USER1@host2( SID=915 )  is blocking ETL_USER@host1( SID=829 )<br />
&#8211; blocked by 915, which funnily enough only active 17 Nov from 17:44 till 22:15 - somehow this session did not release the lock at all until killed the following day<br />
select &#8216;USER&#8217;, sample_time, sql_id, session_state, blocking_session, blocking_session_serial#, blocking_session_status, event,<br />
(select sql_text from DBA_HIST_SQLtext where sql_id=a.sql_id and rownum=1) xxx from dba_hist_active_sess_history  a<br />
where session_id=915 and session_serial#=2165</p>
<p>select * from dba_hist_active_sess_history  a<br />
where session_id=915 and session_serial#=2165 </p>
<p>select *  from dba_tab_columns  where column_name=&#8217;HOST_NAME&#8217; and table_name like &#8216;DBA_HIST%&#8217;</p>
<p>select * from DBA_HIST_SQLbind where sql_id=&#8217;4a2fkw1d4u01u&#8217; and snap_id between 20637 and 20642</p>
]]></content:encoded>
			<wfw:commentRss>http://www.oracleexpert.co.uk/2012/01/ash/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Index Rebuild</title>
		<link>http://www.oracleexpert.co.uk/2012/01/index-rebuild/</link>
		<comments>http://www.oracleexpert.co.uk/2012/01/index-rebuild/#comments</comments>
		<pubDate>Wed, 04 Jan 2012 09:35:34 +0000</pubDate>
		<dc:creator>Hilda</dc:creator>
		
		<category><![CDATA[General]]></category>

		<category><![CDATA[Sandbox]]></category>

		<category><![CDATA[fragmented index]]></category>

		<category><![CDATA[index rebuild]]></category>

		<guid isPermaLink="false">http://www.oracleexpert.co.uk/?p=428</guid>
		<description><![CDATA[The following script can be used to determine which indexes would benefit from a rebuild, how much they will shrink by (assuming 8k block size and 10% pctfree), results ordered by severity. 
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;
select a.*, round(index_leaf_estimate_if_rebuilt/current_leaf_blocks*100) percent, case when index_leaf_estimate_if_rebuilt/current_leaf_blocks < 0.5 then 'candidate for rebuild' end status
from
(
select table_name, index_name, current_leaf_blocks, round (100 / 90 * [...]]]></description>
			<content:encoded><![CDATA[<p>The following script can be used to determine which indexes would benefit from a rebuild, how much they will shrink by (assuming 8k block size and 10% pctfree), results ordered by severity. </p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
select a.*, round(index_leaf_estimate_if_rebuilt/current_leaf_blocks*100) percent, case when index_leaf_estimate_if_rebuilt/current_leaf_blocks < 0.5 then 'candidate for rebuild' end status<br />
from<br />
(<br />
select table_name, index_name, current_leaf_blocks, round (100 / 90 *    (ind_num_rows * (rowid_length + uniq_ind + 4) + sum((avg_col_len) * (tab_num_rows) )   ) / (8192 - 192) ) as index_leaf_estimate_if_rebuilt<br />
from (<br />
select tab.table_name, tab.num_rows tab_num_rows , decode(tab.partitioned,'YES',10,6) rowid_length , ind.index_name, ind.index_type, ind.num_rows ind_num_rows, ind.leaf_blocks as current_leaf_blocks,<br />
 decode(uniqueness,'UNIQUE',0,1) uniq_ind,ic.column_name as ind_column_name, tc.column_name , tc.avg_col_len<br />
from dba_tables tab<br />
join dba_indexes ind on ind.owner=tab.owner and ind.table_name=tab.table_name<br />
join dba_ind_columns ic on ic.table_owner=tab.owner and ic.table_name=tab.table_name and ic.index_owner=tab.owner and ic.index_name=ind.index_name<br />
join dba_tab_columns tc on tc.owner=tab.owner and tc.table_name=tab.table_name and tc.column_name=ic.column_name<br />
where tab.owner='HILDA' and ind.leaf_blocks is not null and ind.leaf_blocks > 1000<br />
) group by table_name, index_name, current_leaf_blocks, ind_num_rows, uniq_ind, rowid_length<br />
) a where index_leaf_estimate_if_rebuilt/current_leaf_blocks < 0.5<br />
order by index_leaf_estimate_if_rebuilt/current_leaf_blocks<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.oracleexpert.co.uk/2012/01/index-rebuild/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Check CPU usage by DB</title>
		<link>http://www.oracleexpert.co.uk/2012/01/check-cpu-usage-by-db/</link>
		<comments>http://www.oracleexpert.co.uk/2012/01/check-cpu-usage-by-db/#comments</comments>
		<pubDate>Tue, 03 Jan 2012 10:25:20 +0000</pubDate>
		<dc:creator>Hilda</dc:creator>
		
		<category><![CDATA[General]]></category>

		<category><![CDATA[Sandbox]]></category>

		<category><![CDATA[performance tuning]]></category>

		<category><![CDATA[topinstance]]></category>

		<guid isPermaLink="false">http://www.oracleexpert.co.uk/?p=425</guid>
		<description><![CDATA[Here is a script originally written by my friend Jim Baker, which I frequently use to check CPU utilisation on a shared DB server by instance
####################
# topinstance.sh
####################
#!/bin/ksh
DBS=`ps -eo args &#124; grep pmon &#124; grep -v grep &#124; cut -c 10-`
PROCS=/tmp/_$$_procs.txt
ps -eoargs,pcpu > $PROCS
for DB in `echo $DBS`
do
  echo `date` $DB `cat $PROCS &#124; grep [...]]]></description>
			<content:encoded><![CDATA[<p>Here is a script originally written by my friend Jim Baker, which I frequently use to check CPU utilisation on a shared DB server by instance</p>
<p>####################<br />
# topinstance.sh<br />
####################<br />
#!/bin/ksh</p>
<p>DBS=`ps -eo args | grep pmon | grep -v grep | cut -c 10-`<br />
PROCS=/tmp/_$$_procs.txt<br />
ps -eoargs,pcpu > $PROCS</p>
<p>for DB in `echo $DBS`<br />
do<br />
  echo `date` $DB `cat $PROCS | grep $DB | grep -v grep | sed &#8217;s/.*  *//&#8217; | \<br />
        awk &#8216;BEGIN { totalcpu = 0.0 } { totalcpu += $0 } END { print totalcpu }&#8217;<br />
`<br />
done</p>
<p>rm -f $PROCS<br />
#####################</p>
<p>This can then be combined with</p>
<p>####################<br />
# pollstat.sh<br />
####################<br />
#!/bin/ksh<br />
touch /home/users/hilda/hostname_usage.log</p>
<p>while [ true ]<br />
do<br />
/home/users/hilda/topinstance.sh >> /home/users/hilda/hostname_usage.log<br />
sleep 30<br />
done</p>
<p>===============</p>
<p>to grab a snapshot every 30 seconds.</p>
<p>This has proven to be useful when combined with AWR reports, so we can quickly determine whether a performance issue is self inflicted within an application, or because some other database is hogging the resource.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.oracleexpert.co.uk/2012/01/check-cpu-usage-by-db/feed/</wfw:commentRss>
		</item>
		<item>
		<title>How to fix unaligned sequence after UAT/DEV refresh</title>
		<link>http://www.oracleexpert.co.uk/2011/12/how-to-fix-unaligned-sequence-after-uatdev-refresh/</link>
		<comments>http://www.oracleexpert.co.uk/2011/12/how-to-fix-unaligned-sequence-after-uatdev-refresh/#comments</comments>
		<pubDate>Thu, 22 Dec 2011 14:39:24 +0000</pubDate>
		<dc:creator>Hilda</dc:creator>
		
		<category><![CDATA[General]]></category>

		<category><![CDATA[sequence]]></category>

		<guid isPermaLink="false">http://www.oracleexpert.co.uk/?p=421</guid>
		<description><![CDATA[Sometimes after a database refresh, we discover that the sequence number has fallen behind compared to actual max value in the table. This then results in PK constraint error when we try to insert a new row using the sequence.
To realign the sequence, you can obviously drop/recreate/alter if you have the right privilege, however here [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes after a database refresh, we discover that the sequence number has fallen behind compared to actual max value in the table. This then results in PK constraint error when we try to insert a new row using the sequence.</p>
<p>To realign the sequence, you can obviously drop/recreate/alter if you have the right privilege, however here is a tip of how to do it if you do not have the schema owner privilege.</p>
<p>declare<br />
  v_table number;<br />
  v_seq   number;<br />
  v_diff  number;<br />
begin<br />
  select max(seq_id) into v_table from TABLE1;<br />
  select last_number into v_seq from all_sequences where sequence_owner=&#8217;OWNER01&#8242; and sequence_name=&#8217;TABLE1_SEQ&#8217; ;</p>
<p>  select v_seq - v_table into v_diff from dual;</p>
<p>  if v_diff < 0<br />
  then<br />
    select (v_diff * -1) + 2 into v_diff from dual;</p>
<p>    for i in 1 .. v_diff<br />
    loop<br />
      select TABLE1_SEQ.nextval into v_table from dual;<br />
    end loop;</p>
<p>  end if;</p>
<p>end;<br />
/</p>
]]></content:encoded>
			<wfw:commentRss>http://www.oracleexpert.co.uk/2011/12/how-to-fix-unaligned-sequence-after-uatdev-refresh/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Trick to slow down rate of LOB fragmentation</title>
		<link>http://www.oracleexpert.co.uk/2011/12/trick-to-slow-down-rate-of-lob-fragmentation/</link>
		<comments>http://www.oracleexpert.co.uk/2011/12/trick-to-slow-down-rate-of-lob-fragmentation/#comments</comments>
		<pubDate>Thu, 22 Dec 2011 14:27:16 +0000</pubDate>
		<dc:creator>Hilda</dc:creator>
		
		<category><![CDATA[General]]></category>

		<category><![CDATA[fragmentation]]></category>

		<category><![CDATA[lob]]></category>

		<guid isPermaLink="false">http://www.oracleexpert.co.uk/?p=419</guid>
		<description><![CDATA[In a traditional table, Oracle stores previous image of the data (due to delete or update actions) in the UNDO tablespace, so this image could be rolled back in case of failure. However for tables with LOBs, oracle uses something different. The previous image of the data is stored inside the table itself, and this [...]]]></description>
			<content:encoded><![CDATA[<p><P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">In a traditional table, Oracle stores previous image of the data (due to delete or update actions) in the UNDO tablespace, so this image could be rolled back in case of failure. However for tables with LOBs, oracle uses something different. The previous image of the data is stored inside the table itself, and this amount of space reserved as the virtual UNDO is controlled by the PCTVERSION parameter.<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p></SPAN></P><br />
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><o:p>&nbsp;</o:p></SPAN></P><br />
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">The default value is 10, meaning 10% of the LOB storage space is reserved for maintaining the old versions of the LOB. The older versions of the LOB data will not be overwritten until they consume 10% of the overall LOB storage space.<o:p></o:p></SPAN></P><br />
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><o:p>&nbsp;</o:p></SPAN></P><br />
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><o:p>In real live, i</o:p></SPAN><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">f you are dealing with LOB datatypes, sometimes you end up with fragmentation in the table. It would seem that even though you have deleted quite a lot of data, when you are inserting, Oracle does not seem to reuse the supposedly freed up space.</P><br />
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><br />
<P><br />
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"></SPAN></P><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><o:p>&nbsp;</o:p></SPAN><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">To get around this problem, we simply set the PCTVERSION down (in our case to 0). The downside of this is you might get an ORA-22924 error (snapshot too old), in which case try to increase it a little. But so far in our case, 0 works fine.<o:p></o:p></SPAN></P></P><br />
<P>Use the storage clause</P><br />
<P>STORE AS (ENABLE STORAGE IN ROW CHUNK 8192 <STRONG>PCTVERSION 0</STRONG> cache STORAGE(BUFFER_POOL DEFAULT)) </P></p>
]]></content:encoded>
			<wfw:commentRss>http://www.oracleexpert.co.uk/2011/12/trick-to-slow-down-rate-of-lob-fragmentation/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Performance Tuning Principles</title>
		<link>http://www.oracleexpert.co.uk/2011/12/performance-tuning-principles/</link>
		<comments>http://www.oracleexpert.co.uk/2011/12/performance-tuning-principles/#comments</comments>
		<pubDate>Thu, 22 Dec 2011 10:47:05 +0000</pubDate>
		<dc:creator>Hilda</dc:creator>
		
		<category><![CDATA[General]]></category>

		<category><![CDATA[performance tuning]]></category>

		<guid isPermaLink="false">http://www.oracleexpert.co.uk/?p=415</guid>
		<description><![CDATA[I am in the middle of handover process, prior to moving to a new project, and was asked to jot down some performance tuning fundamentals that I follow. It is harder than I thought, as how do you fit in 20 years of experience into a short handover document.
But I think the following points would [...]]]></description>
			<content:encoded><![CDATA[<p>I am in the middle of handover process, prior to moving to a new project, and was asked to jot down some performance tuning fundamentals that I follow. It is harder than I thought, as how do you fit in 20 years of experience into a short handover document.</p>
<p>But I think the following points would perhaps be a good start</p>
<p>o	Oracle is a very powerful RDBMS system. Oracle license is <strong>expensive </strong>for a good reason, i.e. it has a lot of functionalities that will benefit the applications if used correctly. Do not treat Oracle simply like a data storage<br />
o	Do not get obsessed with things you can not influence, like disk technology, database OS platform.  90% of performance improvement can be obtained by improving our own design/code.<br />
o	Ensure that your development environment is build as similarly as possible to UAT/Live.<br />
o	Be self sufficient in generating statistics for your tables. Do not rely on DBA overnight jobs. This way we will have full control on the best time and best method to generate the statistics.<br />
o	When choosing an index strategy, make sure you understand how the table is going to be used. Understand the different type of indexes and choose the right ones. Do not OVER indexed.<br />
o	Implement bind variables. Not only this will reduce parsing (memory usage), it will also allow performance investigation to be done more easily.<br />
o	When writing a query with complex joins, the single rule of thumb is, “read as little data as possible” - avoid Full Table Scan and as much as possible, filter first then join, not the other way around<br />
o	Favour bulk operations, rather than row by row, unless you are streaming intraday, or doing manual updates from a front end.<br />
o	Remember sqlldr for data loading<br />
o	Tuning is an ongoing exercise. Keep reviewing the application performance on a regular basis.<br />
o	Think outside the box, performance tuning is more than tuning individual SQL. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.oracleexpert.co.uk/2011/12/performance-tuning-principles/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Converting CSV into rows</title>
		<link>http://www.oracleexpert.co.uk/2011/08/converting-csv-into-rows/</link>
		<comments>http://www.oracleexpert.co.uk/2011/08/converting-csv-into-rows/#comments</comments>
		<pubDate>Wed, 31 Aug 2011 11:30:36 +0000</pubDate>
		<dc:creator>Hilda</dc:creator>
		
		<category><![CDATA[General]]></category>

		<category><![CDATA[Sandbox]]></category>

		<category><![CDATA[convert csv]]></category>

		<category><![CDATA[csv]]></category>

		<guid isPermaLink="false">http://www.oracleexpert.co.uk/?p=412</guid>
		<description><![CDATA[Just  reminder for myself
WITH t AS (
           SELECT &#8216;AAA,a,b,c,d,e,f,g,h,i,j,k,l&#8217; or_str from dual
          )
SELECT  SUBSTR(
               or_str,
      [...]]]></description>
			<content:encoded><![CDATA[<p>Just  reminder for myself<br />
WITH t AS (<br />
           SELECT &#8216;AAA,a,b,c,d,e,f,g,h,i,j,k,l&#8217; or_str from dual<br />
          )<br />
SELECT  SUBSTR(<br />
               or_str,<br />
               INSTR(&#8217;,&#8217; || or_str,&#8217;,',1,LEVEL),<br />
               INSTR(or_str || &#8216;,&#8217;,',&#8217;,1,LEVEL) - INSTR(&#8217;,&#8217; || or_str,&#8217;,',1,LEVEL)<br />
              ) SubString<br />
  FROM  t<br />
  CONNECT BY LEVEL <= LENGTH(or_str)-LENGTH(REPLACE(or_str,&#8217;,')) + 1<br />
     AND PRIOR or_str = or_str<br />
     AND PRIOR DBMS_RANDOM.VALUE IS NOT NULL<br />
/</p>
]]></content:encoded>
			<wfw:commentRss>http://www.oracleexpert.co.uk/2011/08/converting-csv-into-rows/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Easy Way to Reconcile Data</title>
		<link>http://www.oracleexpert.co.uk/2011/08/easy-way-to-reconcile-data/</link>
		<comments>http://www.oracleexpert.co.uk/2011/08/easy-way-to-reconcile-data/#comments</comments>
		<pubDate>Tue, 02 Aug 2011 09:42:38 +0000</pubDate>
		<dc:creator>Hilda</dc:creator>
		
		<category><![CDATA[Finance Systems]]></category>

		<category><![CDATA[General]]></category>

		<category><![CDATA[Design]]></category>

		<category><![CDATA[minus]]></category>

		<category><![CDATA[reconciliation]]></category>

		<guid isPermaLink="false">http://www.oracleexpert.co.uk/?p=410</guid>
		<description><![CDATA[Let&#8217;s say that we need to reconcile data between 2 tables, where we literally need to compare values of each columns and highlight differences between two.
I found the use of MINUS to be very beneficial in letting us do a very quick, yet meaningful reconciliation.
Say you need to reconcile content of TAB1 against content of [...]]]></description>
			<content:encoded><![CDATA[<p>Let&#8217;s say that we need to reconcile data between 2 tables, where we literally need to compare values of each columns and highlight differences between two.</p>
<p>I found the use of MINUS to be very beneficial in letting us do a very quick, yet meaningful reconciliation.</p>
<p>Say you need to reconcile content of TAB1 against content of TAB2.</p>
<p>The outline of the query will look like this<br />
- find items that are in TAB1, but not in TAB2<br />
combine that with<br />
- find items that arein TAB2, but no in TAB1</p>
<p>So your SQL might look like this</p>
<p>(select &#8216;missing from TAB2&#8242; as status, col1,col2,col3,col4,col5,col6 from TAB1<br />
minus<br />
select &#8216;missing from TAB2&#8242; as status col1,col2,col3,col4,col5,col6 from TAB2<br />
)<br />
union all<br />
(<br />
select &#8216;missing from TAB1&#8242; as status, col1,col2,col3,col4,col5,col6 from TAB2<br />
minus<br />
select &#8216;missing from TAB1&#8242; as status, col1,col2,col3,col4,col5,col6 from TAB2<br />
from TAB1)</p>
<p>Easy. I have recently tested to reconcile a 500k row table against another, where each table has 15 columns (even spread between number and varchar2 fields), the reconciliation took just around 10 seconds.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.oracleexpert.co.uk/2011/08/easy-way-to-reconcile-data/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Useful AWR queries</title>
		<link>http://www.oracleexpert.co.uk/2011/07/useful-awr-queries/</link>
		<comments>http://www.oracleexpert.co.uk/2011/07/useful-awr-queries/#comments</comments>
		<pubDate>Fri, 22 Jul 2011 15:44:14 +0000</pubDate>
		<dc:creator>Hilda</dc:creator>
		
		<category><![CDATA[General]]></category>

		<category><![CDATA[Sandbox]]></category>

		<category><![CDATA[AWR]]></category>

		<category><![CDATA[historical performance]]></category>

		<guid isPermaLink="false">http://www.oracleexpert.co.uk/?p=407</guid>
		<description><![CDATA[Often I need to be able to quickly make a judgment on how my databases perform historically.  A bog standard AWR report does not give me the information that I need straight away, and sometimes I do feel overloaded with information that I do not need until I need to drill down to a [...]]]></description>
			<content:encoded><![CDATA[<p>Often I need to be able to quickly make a judgment on how my databases perform historically.  A bog standard AWR report does not give me the information that I need straight away, and sometimes I do feel overloaded with information that I do not need until I need to drill down to a specific problem.</p>
<p>So here are a few queries which I hope you would find useful too</p>
<p><strong>&#8211; historical DB usage day by day by instance</strong><br />
with a<br />
as (select trunc(begin_interval_time) cob, min(snap_id) start_snap_id, max(snap_id) end_snap_id<br />
from dba_hist_snapshot group by trunc(begin_interval_time))<br />
select (select distinct name from gv$database) as db, (select distinct name from gv$database)||case when s.instance_number=1 then &#8216;A&#8217; else &#8216;B&#8217; end as instance,<br />
s.cob, to_char(s.cob,&#8217;Day&#8217;) as day_of_week, s.instance_number, round((end_value-start_value)/1000000/3600) db_time_hours from (<br />
select a.cob, s.instance_number, s.value start_value from dba_hist_sys_time_model s, a where s.snap_id=a.start_snap_id and  s.stat_name=&#8217;DB time&#8217;) s,<br />
(select a.cob, e.instance_number, e.value end_value from dba_hist_sys_time_model e, a where e.snap_id=a.end_snap_id and  e.stat_name=&#8217;DB time&#8217;) e<br />
where s.cob=e.cob and s.instance_number=e.instance_number order by  s.cob desc ,2</p>
<p><strong>&#8211; historical DB usage day by day cummulative both nodes</strong><br />
with a<br />
as (select trunc(begin_interval_time) cob, min(snap_id) start_snap_id, max(snap_id) end_snap_id<br />
from dba_hist_snapshot group by trunc(begin_interval_time))<br />
select (select distinct name from gv$database) as db, s.cob, to_char(s.cob,&#8217;Day&#8217;) as day_of_week, round((end_value-start_value)/1000000/3600) db_time_hours from (<br />
select a.cob, sum(s.value) start_value from dba_hist_sys_time_model s, a where s.snap_id=a.start_snap_id and  s.stat_name=&#8217;DB time&#8217; group by a.cob) s,<br />
(select a.cob,sum(e.value) end_value from dba_hist_sys_time_model e, a where e.snap_id=a.end_snap_id and  e.stat_name=&#8217;DB time&#8217; group by a.cob) e<br />
where s.cob=e.cob order by  s.cob desc ,2</p>
<p><strong>&#8211; historical Physical IO usage day by day by instance</strong><br />
with a<br />
as (select trunc(begin_interval_time) cob, min(snap_id) start_snap_id, max(snap_id) end_snap_id<br />
from dba_hist_snapshot group by trunc(begin_interval_time))<br />
select (select distinct name from gv$database) as db, (select distinct name from gv$database)||case when s.instance_number=1 then &#8216;A&#8217; else &#8216;B&#8217; end as instance,<br />
s.cob, to_char(s.cob,&#8217;Day&#8217;) as day_of_week, s.instance_number, round((end_value-start_value)*8192/1024/1024/1024,2) physical_read_write_gb from (<br />
select a.cob, s.instance_number, sum(s.value) start_value from DBA_HIST_SERVICE_STAT s, a<br />
where s.snap_id=a.start_snap_id and  s.stat_name like &#8216;physical%&#8217; group by a.cob, s.instance_number) s,<br />
(select a.cob, e.instance_number, sum(e.value) end_value from DBA_HIST_SERVICE_STAT e, a<br />
where e.snap_id=a.end_snap_id and  e.stat_name like &#8216;physical%&#8217; group by a.cob, e.instance_number) e<br />
where s.cob=e.cob and s.instance_number=e.instance_number  order by  s.cob desc ,2</p>
<p><strong>&#8211; historical Physical IO usage day by day cummulative both nodes</strong><br />
with a<br />
as (select trunc(begin_interval_time) cob, min(snap_id) start_snap_id, max(snap_id) end_snap_id<br />
from dba_hist_snapshot group by trunc(begin_interval_time))<br />
select (select distinct name from gv$database) as db, s.cob, to_char(s.cob,&#8217;Day&#8217;) as day_of_week,  round((end_value-start_value)*8192/1024/1024/1024,2) physical_read_write_gb from (<br />
select a.cob, sum(s.value) start_value from DBA_HIST_SERVICE_STAT s, a<br />
where s.snap_id=a.start_snap_id and  s.stat_name like &#8216;physical%&#8217; group by a.cob) s,<br />
(select a.cob, sum(e.value) end_value from DBA_HIST_SERVICE_STAT e, a<br />
where e.snap_id=a.end_snap_id and  e.stat_name like &#8216;physical%&#8217; group by a.cob) e<br />
where s.cob=e.cob order by  s.cob desc ,2</p>
<p><strong>&#8211; historical DB usage day by day by service_name cummulative both nodes</strong><br />
with a<br />
as (select trunc(begin_interval_time) cob, min(snap_id) start_snap_id, max(snap_id) end_snap_id<br />
from dba_hist_snapshot group by trunc(begin_interval_time))<br />
select  (select distinct name from gv$database) as db, s.cob, to_char(s.cob,&#8217;Day&#8217;) as day_of_week, s.service_name, round((end_value-start_value)/1000000/3600,2) db_time_hours from (<br />
select a.cob, s.service_name, sum(s.value) start_value from DBA_HIST_SERVICE_STAT s, a<br />
where s.snap_id=a.start_snap_id and  s.stat_name = &#8216;DB time&#8217; group by a.cob, s.service_name) s,<br />
(select a.cob, e.service_name, sum(e.value) end_value from DBA_HIST_SERVICE_STAT e, a<br />
where e.snap_id=a.end_snap_id and  e.stat_name = &#8216;DB time&#8217;  group by a.cob, e.service_name) e<br />
where s.cob=e.cob and s.service_name=e.service_name order by  s.cob desc ,db_time_hours desc</p>
<p><strong>&#8211; Drill down DB time hour by hour by instance</strong><br />
select * from (<br />
select (select distinct name from gv$database) as db, (select distinct name from gv$database)||case when instance_number=1 then &#8216;A&#8217; else &#8216;B&#8217; end as instance, instance_number,<br />
begin_interval_time, end_interval_time, stat_name, db_time_in_hr_by_period, rank() over (partition by instance_number, trunc(begin_interval_time) order by db_time_in_hr_by_period desc) heaviest_period_first<br />
from (<br />
select begin_interval_time, end_interval_time, instance_number, stat_name, round((value-prev_value)/1000000/3600,2) db_time_in_hr_by_period from (<br />
select b.begin_interval_time, b.end_interval_time, a.instance_number, a.stat_name, a.value, lag(a.value,1,0) over (order by a.snap_id) as prev_value<br />
from dba_hist_sys_time_model a,dba_hist_snapshot b<br />
where a.snap_id=b.snap_id and a.stat_name=&#8217;DB time&#8217;<br />
and a.instance_number=b.instance_number<br />
and a.instance_number=1<br />
order by a.snap_id) where prev_value <> 0 )<br />
union all<br />
select (select distinct name from gv$database) as db, (select distinct name from gv$database)||case when instance_number=1 then &#8216;A&#8217; else &#8216;B&#8217; end as instance, instance_number,<br />
begin_interval_time, end_interval_time, stat_name, db_time_in_hr_by_period, rank() over (partition by instance_number, trunc(begin_interval_time) order by db_time_in_hr_by_period desc) heaviest_period_first<br />
from (<br />
select begin_interval_time, end_interval_time, instance_number, stat_name, round((value-prev_value)/1000000/3600,2) db_time_in_hr_by_period from (<br />
select b.begin_interval_time, b.end_interval_time, a.instance_number, a.stat_name, a.value, lag(a.value,1,0) over (order by a.snap_id) as prev_value<br />
from dba_hist_sys_time_model a,dba_hist_snapshot b<br />
where a.snap_id=b.snap_id and a.stat_name=&#8217;DB time&#8217;<br />
and a.instance_number=b.instance_number<br />
and a.instance_number=2<br />
order by a.snap_id) where prev_value <> 0 )<br />
)<br />
order by instance_number desc, trunc(begin_interval_time) desc, heaviest_period_first</p>
]]></content:encoded>
			<wfw:commentRss>http://www.oracleexpert.co.uk/2011/07/useful-awr-queries/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>

