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

<channel>
	<title>Andrew Fraser DBA &#187; Scripts</title>
	<atom:link href="http://andrewfraserdba.com/category/scripts/feed/" rel="self" type="application/rss+xml" />
	<link>http://andrewfraserdba.com</link>
	<description>Oracle DBA (plus SQL Server)</description>
	<lastBuildDate>Wed, 18 Jan 2012 15:25:23 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>unlock orcladmin password in shell script</title>
		<link>http://andrewfraserdba.com/2011/12/05/unlock-orcladmin-password-in-shell-script/</link>
		<comments>http://andrewfraserdba.com/2011/12/05/unlock-orcladmin-password-in-shell-script/#comments</comments>
		<pubDate>Mon, 05 Dec 2011 17:36:29 +0000</pubDate>
		<dc:creator>Andrew Fraser</dc:creator>
				<category><![CDATA[Oracle forms]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[Security]]></category>

		<guid isPermaLink="false">http://andrewfraserdba.com/?p=830</guid>
		<description><![CDATA[Shell script to check if orcladmin account is locked, and unlock it if required # Check to see if orcladmin account is locked, and unlock it if it is. if [ "`ldapbind -p &#60;myport&#62; -D cn=orcladmin -w &#60;myorcladminpassword&#62;`" = "bind &#8230; <a href="http://andrewfraserdba.com/2011/12/05/unlock-orcladmin-password-in-shell-script/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Shell script to check if orcladmin account is locked, and unlock it if required</p>
<pre class="brush:bash, shell"># Check to see if orcladmin account is locked, and unlock it if it is.
if [ "`ldapbind -p &lt;myport&gt; -D cn=orcladmin -w &lt;myorcladminpassword&gt;`" = "bind successful" ]
then
   echo orcladmin account is ok, is not locked.
else
   echo unlocking orcladmin account...
   oidpasswd connect=&lt;mydatabase&gt; unlock_su_acct=true &lt;&lt;END_PASSWD
&lt;mydatabasepassword&gt;
END_PASSWD
fi</pre>
<p>Useful for running from cron for an environment where orcladmin repeatedly gets locked.</p>
<p>The -p port is optional depending on configuration.</p>
]]></content:encoded>
			<wfw:commentRss>http://andrewfraserdba.com/2011/12/05/unlock-orcladmin-password-in-shell-script/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Split space delimited string with regexp SQL</title>
		<link>http://andrewfraserdba.com/2011/07/13/split-space-delimited-string-with-regexp-sql/</link>
		<comments>http://andrewfraserdba.com/2011/07/13/split-space-delimited-string-with-regexp-sql/#comments</comments>
		<pubDate>Wed, 13 Jul 2011 15:53:50 +0000</pubDate>
		<dc:creator>Andrew Fraser</dc:creator>
				<category><![CDATA[Scripts]]></category>

		<guid isPermaLink="false">http://andrewfraserdba.com/?p=721</guid>
		<description><![CDATA[Split up a delimited string with: select regexp_substr('Hello world !' ,'[^ ]+', 1, 1) , regexp_substr('Hello world !' ,'[^ ]+', 1, 2) , regexp_substr('Hello world !' ,'[^ ]+', 1, 3) from dual ; Output: REGEX REGEX R ----- ----- - &#8230; <a href="http://andrewfraserdba.com/2011/07/13/split-space-delimited-string-with-regexp-sql/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Split up a delimited string with:</p>
<pre class="brush:sql">select regexp_substr('Hello world !' ,'[^ ]+', 1, 1)
  , regexp_substr('Hello world !' ,'[^ ]+', 1, 2)
  , regexp_substr('Hello world !' ,'[^ ]+', 1, 3)
from dual ;</pre>
<p>Output:</p>
<pre class="brush:sql">REGEX REGEX R
----- ----- -
Hello world !</pre>
<p>From <a href="http://psoug.org/reference/regexp.html">http://psoug.org/reference/regexp.html</a></p>
]]></content:encoded>
			<wfw:commentRss>http://andrewfraserdba.com/2011/07/13/split-space-delimited-string-with-regexp-sql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>sed change entire line</title>
		<link>http://andrewfraserdba.com/2011/06/08/sed-change-entire-line/</link>
		<comments>http://andrewfraserdba.com/2011/06/08/sed-change-entire-line/#comments</comments>
		<pubDate>Wed, 08 Jun 2011 11:08:22 +0000</pubDate>
		<dc:creator>Andrew Fraser</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Scripts]]></category>

		<guid isPermaLink="false">http://andrewfraserdba.com/?p=715</guid>
		<description><![CDATA[Here I use sed to replace the entire 2nd line in a lot of files with a new 2nd line. The shell script: for fle in `ls *.msg` do # copy file first so as can keep permissions and ownership &#8230; <a href="http://andrewfraserdba.com/2011/06/08/sed-change-entire-line/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Here I use sed to replace the entire 2nd line in a lot of files with a new 2nd line.</p>
<p>The shell script:</p>
<pre class="brush:bash, shell">for fle in `ls *.msg`
do
    # copy file first so as can keep permissions and ownership identical
    cp -p $fle test_$fle
    # replace entire 2nd line with a new 2nd line
    sed -f t.sed $fle > test_$fle
done</pre>
<p>Which calls this sed command file, named t.sed:</p>
<pre class="brush:bash, shell">2c\
\To: dummy.email@me.com</pre>
<p>The result is that the 2nd line in each file reads:
<pre class="brush:bash, shell">To: dummy.email@me.com</pre>
]]></content:encoded>
			<wfw:commentRss>http://andrewfraserdba.com/2011/06/08/sed-change-entire-line/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Remove dba_2pc_pending records</title>
		<link>http://andrewfraserdba.com/2010/12/20/remove-dba_2pc_pending-records/</link>
		<comments>http://andrewfraserdba.com/2010/12/20/remove-dba_2pc_pending-records/#comments</comments>
		<pubDate>Mon, 20 Dec 2010 17:10:15 +0000</pubDate>
		<dc:creator>Andrew Fraser</dc:creator>
				<category><![CDATA[Scripts]]></category>

		<guid isPermaLink="false">http://andrewfraserdba.com/?p=473</guid>
		<description><![CDATA[Old entries in dba_2pc_pending can be removed by &#8216;rollback force&#8217; or if that fails, with a purge: set pages 9999 spool go.tmp select 'rollback force '''&#124;&#124;local_tran_id&#124;&#124;''' ;' from dba_2pc_pending ; select 'exec dbms_transaction.purge_lost_db_entry('''&#124;&#124;local_tran_id&#124;&#124;''' )' , 'commit;' from dba_2pc_pending ; spool &#8230; <a href="http://andrewfraserdba.com/2010/12/20/remove-dba_2pc_pending-records/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Old entries in dba_2pc_pending can be removed by &#8216;rollback force&#8217; or if that fails, with a purge:</p>
<pre  class="brush:sql">set pages 9999
spool go.tmp
select 'rollback force '''||local_tran_id||''' ;' from dba_2pc_pending ;
select 'exec dbms_transaction.purge_lost_db_entry('''||local_tran_id||''' )' , 'commit;' from dba_2pc_pending ;
spool off</pre>
]]></content:encoded>
			<wfw:commentRss>http://andrewfraserdba.com/2010/12/20/remove-dba_2pc_pending-records/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Find delete old files</title>
		<link>http://andrewfraserdba.com/2010/10/29/find-delete-old-files/</link>
		<comments>http://andrewfraserdba.com/2010/10/29/find-delete-old-files/#comments</comments>
		<pubDate>Fri, 29 Oct 2010 08:27:21 +0000</pubDate>
		<dc:creator>Andrew Fraser</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Rman]]></category>
		<category><![CDATA[Scripts]]></category>

		<guid isPermaLink="false">http://andrewfraserdba.com/?p=449</guid>
		<description><![CDATA[# Delete files older than 15 minutes find /ORA_DISK/redoarch/ -name 'arch_*.dbf' -mmin +15 -delete #Delete files older than 2 days 50 8 * * * find /ORA_DISK/redoarch/ -name 'arch_*.dbf' -mtime +2 -delete Old versions of unix find do not have &#8230; <a href="http://andrewfraserdba.com/2010/10/29/find-delete-old-files/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<pre class="brush:bash, shell">#  Delete files older than 15 minutes
find /ORA_DISK/redoarch/ -name 'arch_*.dbf' -mmin +15 -delete

#Delete files older than 2 days
50 8 * * * find /ORA_DISK/redoarch/ -name 'arch_*.dbf' -mtime +2 -delete</pre>
<p>Old versions of unix find do not have the -delete option, so instead:</p>
<pre class="brush:bash, shell">#  Delete files older than 15 minutes
find /ORA_DISK/redoarch/ -name 'arch_*.dbf' -mmin +15 -exec rm {} \;

#Delete files older than 2 days
50 8 * * * find /ORA_DISK/redoarch/ -name 'arch_*.dbf' -mtime +2 -exec rm {} \;</pre>
]]></content:encoded>
			<wfw:commentRss>http://andrewfraserdba.com/2010/10/29/find-delete-old-files/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>HTML formatted emails with utl_smtp</title>
		<link>http://andrewfraserdba.com/2010/09/27/html-formatted-emails-with-utl_smtp/</link>
		<comments>http://andrewfraserdba.com/2010/09/27/html-formatted-emails-with-utl_smtp/#comments</comments>
		<pubDate>Mon, 27 Sep 2010 08:48:13 +0000</pubDate>
		<dc:creator>Andrew Fraser</dc:creator>
				<category><![CDATA[Email]]></category>
		<category><![CDATA[PL/SQL]]></category>
		<category><![CDATA[Scripts]]></category>

		<guid isPermaLink="false">http://andrewfraserdba.com/?p=413</guid>
		<description><![CDATA[HTML format emails allows images, fonts, colours, hyperlinks. It can be done with utl_smtp (after the jump) and with utl_mail -- ask which environment this is, controls who will actually get the emails -- html code needs to use ampersands, &#8230; <a href="http://andrewfraserdba.com/2010/09/27/html-formatted-emails-with-utl_smtp/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>HTML format emails allows images, fonts, colours, hyperlinks. It can be done with utl_smtp (after the jump) and with utl_mail <span id="more-413"></span>
<pre class="brush:sql">-- ask which environment this is, controls who will actually get the emails
-- html code needs to use ampersands, so switch define to instead be another character that isnt used anywhere else
set define }
ACCEPT env PROMPT "Enter Environment (DEV/TEST/LIVE): "

create or replace
PROCEDURE send_mail_cond_reminder
/*
|| Andrew Fraser
|| 8-Jul-2010
|| Sends email html format using utl_smtp
*/
AS
   SENDER   constant VARCHAR2(80) := 'andrew.fraser@mysite.com (Fraser, Andrew)';
   MAILHOST constant VARCHAR2(80) := 'mailhost.mysite.com';
   mail_conn utl_smtp.connection;
   V_CL      constant VARCHAR2(2) := CHR(13)||CHR(10);
   l_rcpt    VARCHAR2(80);
   l_subject VARCHAR2(80)         := 'Email Subject Here';
   l_mesg    VARCHAR2(9900);
   l_body    VARCHAR2(9000);
   CURSOR c_student
   IS
      SELECT s.s_ref,
         s.s_e_mail_address ,
         s.s_forename_1,
         s.s_surname
      FROM students s,
         e_user_com c,
         e_user_id i,
         ab_reg a
      WHERE s.s_ref = i.s_ref
      AND i.s_ref   = c.s_ref
      AND s.s_e_mail_address IS NOT NULL
      -- Check student has reg'd this year
      AND i.ereg_year = a.ab_r_year
      -- Report just for people who have not yet had an email sent to them
      AND c.password_set_datetime IS NOT NULL
      AND c.cond_reminder_email_sent IS NULL
      ORDER BY 1 FOR UPDATE OF c.cond_reminder_email_sent ;
BEGIN
   mail_conn := utl_smtp.open_connection(mailhost, 25) ;
   utl_smtp.helo(mail_conn, MAILHOST) ;
   FOR d_student IN c_student
   LOOP
      dbms_output.put_line('Sending Email to : ' || d_student.s_e_mail_address ) ;
      BEGIN
         l_body :=

'&lt; html&gt;&lt; head&gt;&lt; title&gt;Email Title Here&lt; /title&gt;&lt; /head&gt;&lt; body&gt;'||v_cl||v_cl||
'&lt; table width="100%" cellpadding="10" cellspacing="0"&gt;'||v_cl||v_cl||
'&lt; tr&gt;'||v_cl||v_cl||
'&lt; span style=''font-family:Calibri,Arial,Helvetica,sans-serif''&gt;'||v_cl||v_cl||

'&lt; p&gt;Dear '|| INITCAP(d_student.s_forename_1) ||' '|| INITCAP(d_student.s_surname)||','||v_cl||v_cl||

'&lt; br&gt;&lt; br&gt;There have been a number of significant changes to service over the summer and this E-mail is to make sure you are aware of them:'||v_cl||v_cl||

'&lt; span style=''color: DarkBlue''&gt;'||v_cl||v_cl||
'&lt; ul&gt;&lt; li&gt;Revised opening hours and function of the reception window'||v_cl||v_cl||
'&lt; li&gt;Colour printing'||v_cl||v_cl||
'&lt; li&gt;Changes to FreePCs display'||v_cl||v_cl||
'&lt; li&gt;Windows 7'||v_cl||v_cl||
'&lt; li&gt;Report problems with wireless or we can''t fix'||v_cl||v_cl||
'&lt; li&gt;Power saving'||v_cl||v_cl||
'&lt; li&gt;Backing up your data / work'||v_cl||v_cl||
'&lt; li&gt;Illegal copyright downloads'||v_cl||v_cl||

'&lt; /ul&gt;&lt; /span&gt;&lt; span style=''font-weight:bold; color: SteelBlue; font-family:Cambria,Calibri,Arial,Helvetica,sans-serif''&gt;'||v_cl||v_cl||
'&lt; p&gt;Revised opening hours and function of the reception window&lt; /span&gt;'||v_cl||v_cl||

'&lt; br&gt;&lt; br&gt;From 5th July 2010 the reception window will open 08:30 - 10:30 and 12:30 - 14:30 and only to allow for cash payments to top up print budgets; the minimum charge for this is still £3.  Printing budgets can still be topped up via the portal or at Library at weekends or after 6pm weekdays. ( Full details about printing can be found at: &lt; a href="http://mysite.com/print/index.php"&gt;mysite.com/student/print/index.php&lt; /a&gt; ). All other queries should be directed to the ServiceDesk instead of the reception window ( further details on the ServiceDesk can be found at: &lt; a href="http://mysite.com/servicedesk/index.php"&gt;mysite.com/servicedesk/index.php&lt; /a&gt; )'||v_cl||v_cl||

'&lt; span style=''font-weight:bold; color: SteelBlue; font-family:Cambria,Calibri,Arial,Helvetica,sans-serif''&gt;'||v_cl||v_cl||
'&lt; br&gt;&lt; br&gt;Colour printing service changes&lt; /span&gt;'||v_cl||v_cl||

'&lt; br&gt;&lt; br&gt;As the reception window is now only available for topping up print budgets the colour printer has been moved and is now accessed via a new colour classroom printstations holding queue. There are checks in place to ensure that you don''t try to print colour output on a monochrome printer and vice versa. Further details are available at: &lt; a href="http://mysite.com/student/news/index_1873.php"&gt;mysite.com/student/news/index_1873.php&lt; /a&gt;'||v_cl||v_cl||

'&lt; span style=''font-weight:bold; color: SteelBlue; font-family:Cambria,Calibri,Arial,Helvetica,sans-serif''&gt;'||v_cl||v_cl||
'&lt; br&gt;&lt; br&gt;Information on booked and free classrooms&lt; /span&gt;'||v_cl||v_cl||

'&lt; br&gt;&lt; br&gt;In the annual survey to students a number of you commented on the fact that often the notices on the door of many PC classrooms were incorrect / out of date and also that there was no way of knowing if a room was booked, or any machines were free without going to the relevant room. In response to these comments we have looked at this and decided that we will replace the paper notices with screen displays in a number of buildings. These displays will provide information on which rooms are free or booked and also how many machines are currently being used in each room. The course code, where available, for booked rooms will be shown as well as the duration or time of next booking. To see what the display looks like see: &lt; a href="http://mysite.com/freepcs/"&gt;mysite.com/freepcs/&lt; /a&gt;'||v_cl||v_cl||

'&lt; span style=''font-weight:bold; color: SteelBlue; font-family:Cambria,Calibri,Arial,Helvetica,sans-serif''&gt;'||v_cl||v_cl||
'&lt; br&gt;&lt; br&gt;Windows 7 and new machines&lt; /span&gt;'||v_cl||v_cl||

'&lt; br&gt;&lt; br&gt;From August 2010 we will be installing the new classroom image which will be based on Windows 7 so that on your return you will see the new, improved classroom images. We will also etc etc etc etc etc'||v_cl||v_cl||

'&lt; br&gt;&lt; br&gt;&lt; i&gt;Best wishes'||v_cl||v_cl||
'&lt; br&gt;&lt; br&gt;You name here'||v_cl||v_cl||
'&lt; br&gt;&lt; a href="http://mysite.com/"&gt;Title&lt; /a&gt; ( Title ) - &lt; a href="http://mysite.com/slo/"&gt;Full Title&lt; /a&gt;'||v_cl||v_cl||
'&lt; /i&gt;&lt; /p&gt;&lt; /span&gt;&lt; /table&gt;&lt; /body&gt;&lt; /html&gt;' ;

         l_mesg := 'Date: '||TO_CHAR(sysdate,'dd Mon yy hh24:mi:ss')||V_CL||
             'From: &lt; '||SENDER||'&gt;'||V_CL||
             'Subject: '||l_subject||V_CL||
             'To: '|| d_student.s_e_mail_address ||v_cl||
             'MIME-Version: 1.0'||V_CL||
             'Content-type:text/html;charset=iso-8859-1'||V_CL||
             ''||v_cl||l_body ;
         utl_smtp.mail(mail_conn, SENDER) ;

         if upper('}env') = 'DEV' then
             l_rcpt := 'andrew.fraser@mysite.com';               -- For Development
         elsif upper('}env') = 'TEST' then
             l_rcpt := 'tester@mysite.com';         -- For Test
         else
             l_rcpt := d_student.s_e_mail_address;
         end if;
         utl_smtp.rcpt(mail_conn, l_rcpt) ;

         utl_smtp.data(mail_conn, l_mesg) ;
         -- Update email_sent field so that we do not email this student again
         UPDATE e_user_com
            SET cond_reminder_email_sent = SYSDATE
            WHERE CURRENT OF c_student ;
      EXCEPTION
         WHEN utl_smtp.transient_error OR utl_smtp.permanent_error THEN
            NULL ;
         WHEN OTHERS THEN
            dbms_output.put_line('Error Code : ' || SQLCODE) ;
            dbms_output.put_line('Error Message : ' || SQLERRM) ;
            EXIT ;
      END ;
   END LOOP ;
   utl_smtp.quit(mail_conn) ;
END ;
/
</pre>
]]></content:encoded>
			<wfw:commentRss>http://andrewfraserdba.com/2010/09/27/html-formatted-emails-with-utl_smtp/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Select out all code refererencing some tables</title>
		<link>http://andrewfraserdba.com/2010/08/26/select-out-all-code-refererencing-some-tables/</link>
		<comments>http://andrewfraserdba.com/2010/08/26/select-out-all-code-refererencing-some-tables/#comments</comments>
		<pubDate>Thu, 26 Aug 2010 11:47:52 +0000</pubDate>
		<dc:creator>Andrew Fraser</dc:creator>
				<category><![CDATA[Scripts]]></category>

		<guid isPermaLink="false">http://andrewfraserdba.com/?p=404</guid>
		<description><![CDATA[This allows you to get code listings for all code (procedures, views, materialized views, etc.) that reference particular tables: set long 200000 pages 0 verify off lines 131 feed off column txt format a121 word_wrapped column spoolfile new_value spoolfile noprint &#8230; <a href="http://andrewfraserdba.com/2010/08/26/select-out-all-code-refererencing-some-tables/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>This allows you to get code listings for all code (procedures, views, materialized views, etc.) that reference particular tables:</p>
<pre  class="brush:sql">set long 200000 pages 0 verify off lines 131 feed off
column txt format a121 word_wrapped
column spoolfile new_value spoolfile noprint
spool go.tmp
select '@2 '|| decode(type , 'MATERIALIZED VIEW' , 'MATERIALIZED_VIEW' , type)  ||' '||name||' '||owner
from dba_dependencies where referenced_name in ('TABLE1','TABLE2','TABLE3')
order by 1 ;
spool off
@go.tmp</pre>
<p>That calls files 2.sql which contains:</p>
<pre  class="brush:sql">select lower( '&#038;1' ||'.'|| '&#038;2' || '.sql' ) spoolfile from dual ;
spool &#038;spoolfile
select dbms_metadata.get_ddl('&#038;1','&#038;2','&#038;3') txt from dual;
spool off</pre>
]]></content:encoded>
			<wfw:commentRss>http://andrewfraserdba.com/2010/08/26/select-out-all-code-refererencing-some-tables/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Make indexes unusable before big insert</title>
		<link>http://andrewfraserdba.com/2010/07/30/make-indexes-unusable-before-big-insert/</link>
		<comments>http://andrewfraserdba.com/2010/07/30/make-indexes-unusable-before-big-insert/#comments</comments>
		<pubDate>Fri, 30 Jul 2010 13:55:39 +0000</pubDate>
		<dc:creator>Andrew Fraser</dc:creator>
				<category><![CDATA[Scripts]]></category>

		<guid isPermaLink="false">http://andrewfraserdba.com/?p=396</guid>
		<description><![CDATA[Make indexes unusable before doing a big insert, then rebuild them at the end, is faster than insert with indexes in place and no risk of forgetting to recreate a dropped index: create table af ( mycol varchar2(100) ) ; &#8230; <a href="http://andrewfraserdba.com/2010/07/30/make-indexes-unusable-before-big-insert/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Make indexes unusable before doing a big insert, then rebuild them at the end, is faster than insert with indexes in place and no risk of forgetting to recreate a dropped index:</p>
<pre  class="brush:sql">create table af ( mycol varchar2(100) ) ;
create index af1 on af ( mycol ) ;
alter index af1 unusable ;
insert into af (mycol) select * from big_table ;
select status from dba_indexes where index_name = 'AF1' ;
alter index af1 rebuild ;
select status from dba_indexes where index_name = 'AF1' ;</pre>
<p>Code to make a lot of indexes unusable in one go is:</p>
<pre  class="brush:sql">select 'alter index '||owner||'.'||index_name||' unusable ;'
from dba_indexes
where owner = 'MYSCHEMA' ;</pre>
]]></content:encoded>
			<wfw:commentRss>http://andrewfraserdba.com/2010/07/30/make-indexes-unusable-before-big-insert/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Move objects including lobs, xml to new tablespace with dynamic SQL</title>
		<link>http://andrewfraserdba.com/2010/05/03/move-objects-including-lobs-xml-to-new-tablespace-with-dynamic-sql/</link>
		<comments>http://andrewfraserdba.com/2010/05/03/move-objects-including-lobs-xml-to-new-tablespace-with-dynamic-sql/#comments</comments>
		<pubDate>Mon, 03 May 2010 16:04:51 +0000</pubDate>
		<dc:creator>Andrew Fraser</dc:creator>
				<category><![CDATA[Scripts]]></category>
		<category><![CDATA[Space]]></category>

		<guid isPermaLink="false">http://andrewfraserdba.com/?p=243</guid>
		<description><![CDATA[Here objects are moved from tablespace users to tablespace users1: set pages 9999 lines 132 spool m2.sql select 'alter table '&#124;&#124;owner&#124;&#124;'.'&#124;&#124;table_name&#124;&#124;' move lob('&#124;&#124;column_name&#124;&#124;') store as ( tablespace users1);' from dba_lobs where tablespace_name = 'USERS' order by 1 / select 'alter &#8230; <a href="http://andrewfraserdba.com/2010/05/03/move-objects-including-lobs-xml-to-new-tablespace-with-dynamic-sql/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Here objects are moved from tablespace users to tablespace users1:</p>
<pre class="brush:sql">set pages 9999 lines 132
spool m2.sql
select 'alter table '||owner||'.'||table_name||' move lob('||column_name||') store as ( tablespace users1);'
from dba_lobs where tablespace_name = 'USERS' order by 1
/
select 'alter table '||owner||'.'||segment_name||' move tablespace users1;'
from dba_segments where tablespace_name = 'USERS' and segment_type = 'TABLE' order by 1
/
select 'alter index '||owner||'.'||index_name||' rebuild tablespace users1;'
from dba_indexes where tablespace_name = 'USERS' order by 1
/
spool off
ed m2</pre>
]]></content:encoded>
			<wfw:commentRss>http://andrewfraserdba.com/2010/05/03/move-objects-including-lobs-xml-to-new-tablespace-with-dynamic-sql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PL/SQL to count from all tables in a schema</title>
		<link>http://andrewfraserdba.com/2010/03/12/plsql-to-count-from-all-tables-in-a-schema/</link>
		<comments>http://andrewfraserdba.com/2010/03/12/plsql-to-count-from-all-tables-in-a-schema/#comments</comments>
		<pubDate>Fri, 12 Mar 2010 16:51:03 +0000</pubDate>
		<dc:creator>Andrew Fraser</dc:creator>
				<category><![CDATA[Scripts]]></category>

		<guid isPermaLink="false">http://andrewfraserdba.com/?p=218</guid>
		<description><![CDATA[Replace SYSTEM with the name of the schema you are interested in: set serverout on size 999999 declare cnt number ; begin for c1 in (select owner, table_name from all_tables where owner = 'SYSTEM') loop execute immediate 'select count(1) from &#8230; <a href="http://andrewfraserdba.com/2010/03/12/plsql-to-count-from-all-tables-in-a-schema/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Replace SYSTEM with the name of the schema you are interested in:</p>
<pre class="brush:sql">set serverout on size 999999
declare
  cnt number ;
begin
  for c1 in (select owner, table_name from all_tables where owner = 'SYSTEM')
  loop
    execute immediate 'select count(1) from '||c1.owner||'.'||c1.table_name into cnt ;
    dbms_output.put_line(c1.table_name||','||cnt) ;
  end loop ;
end ;
/</pre>
]]></content:encoded>
			<wfw:commentRss>http://andrewfraserdba.com/2010/03/12/plsql-to-count-from-all-tables-in-a-schema/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

