<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Oracle on dwmkerr.com</title><link>https://dwmkerr.com/categories/oracle/</link><description>Recent content in Oracle on dwmkerr.com</description><generator>Hugo -- gohugo.io</generator><language>en-uk</language><managingEditor>Dave Kerr</managingEditor><copyright>Copright &amp;copy; Dave Kerr</copyright><lastBuildDate>Fri, 24 Feb 2012 06:20:00 +0000</lastBuildDate><atom:link href="https://dwmkerr.com/categories/oracle/index.xml" rel="self" type="application/rss+xml"/><item><title>Disabling Constraints with a Stored Procedure in Oracle</title><link>https://dwmkerr.com/disabling-constraints-with-a-stored-procedure-in-oracle/</link><pubDate>Fri, 24 Feb 2012 06:20:00 +0000</pubDate><guid>https://dwmkerr.com/disabling-constraints-with-a-stored-procedure-in-oracle/</guid><description>&lt;p&gt;Sometimes you need to disable constraints on a Oracle Database. Why might this be? Well image the situation that you are exporting data into an intermediate schema, you only want to import data from a certain date range and due to this you have only a subset of the records. You need this subset for analysis but you don't care about referential integrity - in fact if it is on then constraints will be violated. How can we do this?&lt;/p&gt;
&lt;p&gt;Here's a stored procedure that disables constraints for tables owned by 'UserName1' or 'UserName2':&lt;/p&gt;
&lt;pre&gt;CREATE OR REPLACE PROCEDURE extraction.sp_PrepExtractionDatabase&amp;nbsp;&lt;/pre&gt;
&lt;pre&gt;AUTHID CURRENT_USER&lt;/pre&gt;
&lt;pre&gt;IS&amp;nbsp;&lt;/pre&gt;
&lt;pre&gt;&amp;nbsp; &amp;nbsp; v_Statement VARCHAR(5000);&lt;/pre&gt;
&lt;pre&gt;BEGIN &amp;nbsp;&lt;/pre&gt;
&lt;pre&gt;&amp;nbsp; &amp;nbsp; FOR const in (CURSOR c_Constraints IS&lt;/pre&gt;
&lt;pre&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; SELECT constraint_name, table_name, owner&lt;/pre&gt;
&lt;pre&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; FROM ALL_CONSTRAINTS&lt;/pre&gt;
&lt;pre&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; WHERE owner IN ('UserName1', 'UserName2')) LOOP&lt;/pre&gt;
&lt;pre&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; v_Statement := 'ALTER TABLE ' || const.owner &lt;br /&gt;|| '.' || const.table_name || ' DISABLE CONSTRAINT '&lt;br /&gt; || const.constraint_name;&lt;/pre&gt;
&lt;pre&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; EXECUTE IMMEDIATE v_Statement;&lt;/pre&gt;
&lt;pre&gt;&amp;nbsp; &amp;nbsp; END LOOP;&lt;/pre&gt;
&lt;pre&gt;END;&lt;/pre&gt;
&lt;pre&gt;/&lt;/pre&gt;
&lt;p&gt;What's the key thing here? 'AUTHID CURRENT_USER'. Without this, running the query itself will work fine, but the stored procedure will find NOTHING in the ALL_CONSTRAINTS view. Run in the context of the current user and then the stored procedure will work fine.&lt;/p&gt;</description><category>CodeProject</category></item><item><title>Using imp or exp as a SYSDBA</title><link>https://dwmkerr.com/using-imp-or-exp-as-a-sysdba/</link><pubDate>Tue, 21 Feb 2012 07:21:00 +0000</pubDate><guid>https://dwmkerr.com/using-imp-or-exp-as-a-sysdba/</guid><description>&lt;p&gt;One of the things that I regularly forget is the syntax for running imp or exp for Oracle and specifying a SYSDBA user. As a quick hint, here's the syntax:&lt;/p&gt;
&lt;pre class="brush: c-sharp;"&gt;imp '"sys/pass@TNS as sysdba"' FILE=file.exp&lt;/pre&gt;
&lt;p&gt;An easy thing to forget!&lt;/p&gt;</description><category>CodeProject</category></item></channel></rss>