<?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>hocuspokus &#187; oracle</title>
	<atom:link href="http://hocuspokus.net/category/oracle/feed" rel="self" type="application/rss+xml" />
	<link>http://hocuspokus.net</link>
	<description>the life and times of a code monkey</description>
	<lastBuildDate>Fri, 12 Mar 2010 15:57:13 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Installing the Ruby Bindings for Oracle on Mac OS&#160;X</title>
		<link>http://hocuspokus.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fhocuspokus.net%2F2010%2F03%2Finstalling-the-ruby-bindings-for-oracle-on-mac-os-x&amp;seed_title=Installing+the+Ruby+Bindings+for+Oracle+on+Mac+OS%26%23160%3BX</link>
		<comments>http://hocuspokus.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fhocuspokus.net%2F2010%2F03%2Finstalling-the-ruby-bindings-for-oracle-on-mac-os-x&amp;seed_title=Installing+the+Ruby+Bindings+for+Oracle+on+Mac+OS%26%23160%3BX#comments</comments>
		<pubDate>Thu, 04 Mar 2010 09:36:56 +0000</pubDate>
		<dc:creator>Daz</dc:creator>
				<category><![CDATA[mac]]></category>
		<category><![CDATA[oracle]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[gem]]></category>
		<category><![CDATA[install]]></category>

		<guid isPermaLink="false">http://hocuspokus.net/?p=410</guid>
		<description><![CDATA[This quick crib sheet is for the guys at work (and anyone else who might need help on this one)&#8230;

First install the oracle instant client somewhere - I normally install it to /usr/local/oracle/instantclient_10_2.  Then&#8230;


cd /usr/local/oracle/instantclient_10_2
ln -s libclntsh.dylib.10.1 libclntsh.dylib


Following this, run mkdir -p /usr/local/oracle/network/admin/, and place a copy of the tnsnames.ora file in this directory.

Now [...]]]></description>
			<content:encoded><![CDATA[<p>This quick crib sheet is for the guys at work (and anyone else who might need help on this one)&#8230;</p>

<p>First install the <a href="http://www.oracle.com/technology/software/tech/oci/instantclient/index.html">oracle instant client</a> somewhere - I normally install it to <code>/usr/local/oracle/instantclient_10_2</code>.  Then&#8230;</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>oracle<span style="color: #000000; font-weight: bold;">/</span>instantclient_10_2
<span style="color: #c20cb9; font-weight: bold;">ln</span> <span style="color: #660033;">-s</span> libclntsh.dylib.10.1 libclntsh.dylib</pre></div></div>


<p>Following this, run <code>mkdir -p /usr/local/oracle/network/admin/</code>, and place a copy of the tnsnames.ora file in this directory.</p>

<p>Now you need to add the following to your <code>.profile</code> or <code>.bashrc</code> file:</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># Oracle env variables</span>
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">ORACLE_HOME</span>=<span style="color: #ff0000;">&quot;/usr/local/oracle/instantclient_10_2&quot;</span>
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">DYLD_LIBRARY_PATH</span>=<span style="color: #ff0000;">&quot;/usr/local/oracle/instantclient_10_2:<span style="color: #007800;">$DYLD_LIBRARY_PATH</span>&quot;</span>
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">SQLPATH</span>=<span style="color: #ff0000;">&quot;/usr/local/oracle/instantclient_10_2&quot;</span>
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">TNS_ADMIN</span>=<span style="color: #ff0000;">&quot;/usr/local/oracle/network/admin&quot;</span>
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">NLS_LANG</span>=<span style="color: #ff0000;">&quot;AMERICAN_AMERICA.UTF8&quot;</span>
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">PATH</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$PATH</span>:<span style="color: #007800;">$DYLD_LIBRARY_PATH</span>&quot;</span></pre></div></div>


<p>That&#8217;s all of the set-up done, now you just need to install the gem:</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">gem <span style="color: #c20cb9; font-weight: bold;">install</span> ruby-oci8</pre></div></div>


<p>Done. <img src='http://hocuspokus.net/wp-content/plugins/smilies-themer/tango/face-smile.png' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://hocuspokus.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fhocuspokus.net%2F2010%2F03%2Finstalling-the-ruby-bindings-for-oracle-on-mac-os-x&amp;seed_title=Installing+the+Ruby+Bindings+for+Oracle+on+Mac+OS%26%23160%3BX/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Remove Case-Sensitivity in&#160;Oracle</title>
		<link>http://hocuspokus.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fhocuspokus.net%2F2007%2F10%2Fremove-case-sensitivity-in-oracle&amp;seed_title=Remove+Case-Sensitivity+in%26%23160%3BOracle</link>
		<comments>http://hocuspokus.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fhocuspokus.net%2F2007%2F10%2Fremove-case-sensitivity-in-oracle&amp;seed_title=Remove+Case-Sensitivity+in%26%23160%3BOracle#comments</comments>
		<pubDate>Thu, 18 Oct 2007 16:06:42 +0000</pubDate>
		<dc:creator>Daz</dc:creator>
				<category><![CDATA[oracle]]></category>
		<category><![CDATA[perl]]></category>

		<guid isPermaLink="false">http://hocuspokus.net/2007/10/18/remove-case-sensitivity-in-oracle/</guid>
		<description><![CDATA[Oracle is a great RDBMS, but the fact that searches against the database are case-sensitive can be a pain in the butt.  Here&#8217;s how you can make searches case-insensitive&#8230;



In SQL&#8230;


1
2
ALTER session SET NLS_SORT=BINARY_CI;
ALTER session SET NLS_COMP=LINGUISTIC;


For use in Perl::DBI&#8230;


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
use strict;
use DBI;
&#160;
my $dbh = DBI-&#62;connect&#40;
    'dbi:Oracle:schema_name',
    'user',
   [...]]]></description>
			<content:encoded><![CDATA[<p>Oracle is a great RDBMS, but the fact that searches against the database are case-sensitive can be a pain in the butt.  Here&#8217;s how you can make searches case-insensitive&#8230;</p>

<p><span id="more-37"></span></p>

<p>In SQL&#8230;</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">ALTER</span> session <span style="color: #993333; font-weight: bold;">SET</span> NLS_SORT<span style="color: #66cc66;">=</span>BINARY_CI;
<span style="color: #993333; font-weight: bold;">ALTER</span> session <span style="color: #993333; font-weight: bold;">SET</span> NLS_COMP<span style="color: #66cc66;">=</span>LINGUISTIC;</pre></td></tr></table></div>


<p>For use in Perl::DBI&#8230;</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
</pre></td><td class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">use</span> strict<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">use</span> DBI<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$dbh</span> <span style="color: #339933;">=</span> DBI<span style="color: #339933;">-&gt;</span><span style="color: #006600;">connect</span><span style="color: #009900;">&#40;</span>
    <span style="color: #ff0000;">'dbi:Oracle:schema_name'</span><span style="color: #339933;">,</span>
    <span style="color: #ff0000;">'user'</span><span style="color: #339933;">,</span>
    <span style="color: #ff0000;">'password'</span><span style="color: #339933;">,</span>
    <span style="color: #009900;">&#123;</span>
        RaiseError    <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span>
        AutoCommit    <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span>
        on_connect_do <span style="color: #339933;">=&gt;</span> <span style="color: #009900;">&#91;</span>
            <span style="color: #ff0000;">'alter session set NLS_SORT=BINARY_CI'</span><span style="color: #339933;">,</span>
            <span style="color: #ff0000;">'alter session set NLS_COMP=LINGUISTIC'</span>
        <span style="color: #009900;">&#93;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #000066;">die</span> <span style="color: #ff0000;">&quot;Database connection not made: $DBI::errstr&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #0000ff;">$dbh</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">disconnect</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://hocuspokus.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fhocuspokus.net%2F2007%2F10%2Fremove-case-sensitivity-in-oracle&amp;seed_title=Remove+Case-Sensitivity+in%26%23160%3BOracle/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL 4.X to Oracle&#160;Notes</title>
		<link>http://hocuspokus.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fhocuspokus.net%2F2007%2F10%2Fmysql-4x-to-oracle-notes&amp;seed_title=MySQL+4.X+to+Oracle%26%23160%3BNotes</link>
		<comments>http://hocuspokus.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fhocuspokus.net%2F2007%2F10%2Fmysql-4x-to-oracle-notes&amp;seed_title=MySQL+4.X+to+Oracle%26%23160%3BNotes#comments</comments>
		<pubDate>Thu, 11 Oct 2007 17:12:45 +0000</pubDate>
		<dc:creator>Daz</dc:creator>
				<category><![CDATA[mysql]]></category>
		<category><![CDATA[oracle]]></category>
		<category><![CDATA[snippets]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://hocuspokus.net/2007/10/11/mysql-4x-to-oracle-notes/</guid>
		<description><![CDATA[Stumbled across this useful page full of examples and notes on how MySQL 4.x and Oracle differ, and how you can avoid complications if you want to migrate a database between the two&#8230;


  About once a year I need to migrate a medium-sized web application using MySQL to Oracle.
  
  Usually itâ€™s [...]]]></description>
			<content:encoded><![CDATA[<p>Stumbled across this useful page full of examples and notes on how MySQL 4.x and Oracle differ, and how you can avoid complications if you want to migrate a database between the two&#8230;</p>

<blockquote>
  <p>About once a year I need to migrate a medium-sized web application using MySQL to Oracle.</p>
  
  <p>Usually itâ€™s to prepare a successful intranet application for a move to a formally supported production environment - and in Silicon Valley, that usually means Oracle.</p>
  
  <p>I was apologizing to Monty at OSCON this year about my latest migration project away from MySQL.</p>
  
  <p>His surprising response was, &#8220;Itâ€™s not a bad thing. I donâ€™t mind hearing about conversions because successful migrations demonstrate that people donâ€™t have to worry about database lock-in.&#8221;</p>
  
  <p>Hereâ€™s some notes on doing migrations.</p>
</blockquote>

<p><a href="http://www.jebriggs.com/blog/oscon/mysql-4x-to-oracle-10g-migration-notes.html" class="via">read more</a></p>
<a href="http://hocuspokus.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fhocuspokus.net%2F2007%2F10%2Fmysql-4x-to-oracle-notes&amp;seed_title=MySQL+4.X+to+Oracle%26%23160%3BNotes" rel="bookmark" class="asides-permalink" title="Permanent Link to MySQL 4.X to Oracle&nbsp;Notes">(0)</a>]]></content:encoded>
			<wfw:commentRss>http://hocuspokus.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fhocuspokus.net%2F2007%2F10%2Fmysql-4x-to-oracle-notes&amp;seed_title=MySQL+4.X+to+Oracle%26%23160%3BNotes/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Log/Audit Tables in&#160;Oracle</title>
		<link>http://hocuspokus.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fhocuspokus.net%2F2007%2F10%2Flogaudit-tables-in-oracle&amp;seed_title=Log%2FAudit+Tables+in%26%23160%3BOracle</link>
		<comments>http://hocuspokus.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fhocuspokus.net%2F2007%2F10%2Flogaudit-tables-in-oracle&amp;seed_title=Log%2FAudit+Tables+in%26%23160%3BOracle#comments</comments>
		<pubDate>Fri, 05 Oct 2007 12:07:06 +0000</pubDate>
		<dc:creator>Daz</dc:creator>
				<category><![CDATA[noteworthy]]></category>
		<category><![CDATA[oracle]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://hocuspokus.net/2007/10/05/logaudit-tables-in-oracle/</guid>
		<description><![CDATA[One of the useful things that i&#8217;ve been asked to set-up lately is automatic logging of changes to several of our database tables.

My first thought was to do this in Perl (as the rest of the system is in Perl), but this would mean adding extra methods and calls in the Perl code to update [...]]]></description>
			<content:encoded><![CDATA[<p>One of the useful things that i&#8217;ve been asked to set-up lately is automatic logging of changes to several of our database tables.</p>

<p>My first thought was to do this in Perl (as the rest of the system is in Perl), but this would mean adding extra methods and calls in the Perl code to update the database (both the original tables and the new log tables).  That seemed like a solution - a pain in the arse to implement, but a solution.</p>

<p>Thankfully one of the helpful chaps in my department suggested doing it all in the database with triggers as this is quite common in banks and the like.  What a damn fine idea!  Only a little SQL to write and no extra Perl.</p>

<p><span id="more-24"></span></p>

<p>Here&#8217;s an example&#8230;</p>

<p>First, here&#8217;s the table that we want to create an audit log for:</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> <span style="color: #ff0000;">&quot;COMMENT&quot;</span> <span style="color: #66cc66;">&#40;</span>
  <span style="color: #ff0000;">&quot;COMMENT_ID&quot;</span> NUMBER<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">10</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span> 
  <span style="color: #ff0000;">&quot;COMMENT_BODY&quot;</span> VARCHAR2<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1000</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> 
  <span style="color: #ff0000;">&quot;USER&quot;</span> VARCHAR2<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">100</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> 
  <span style="color: #ff0000;">&quot;CREATED_DATE&quot;</span> DATE<span style="color: #66cc66;">,</span> 
  CONSTRAINT <span style="color: #ff0000;">&quot;PK_COMMENT&quot;</span> <span style="color: #993333; font-weight: bold;">PRIMARY</span> <span style="color: #993333; font-weight: bold;">KEY</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;COMMENT_ID&quot;</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#41;</span>;</pre></td></tr></table></div>


<p>Now, we create the audit table.<sup id="fnref:1"><a href="#fn:1" rel="footnote">1</a></sup></p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> <span style="color: #ff0000;">&quot;COMMENT_AUDIT&quot;</span> <span style="color: #66cc66;">&#40;</span>
  <span style="color: #ff0000;">&quot;COMMENT_ID&quot;</span> NUMBER<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">10</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span> 
  <span style="color: #ff0000;">&quot;COMMENT_BODY&quot;</span> VARCHAR2<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1000</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> 
  <span style="color: #ff0000;">&quot;USER&quot;</span> VARCHAR2<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">100</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> 
  <span style="color: #ff0000;">&quot;CREATED_DATE&quot;</span> DATE<span style="color: #66cc66;">,</span>
  <span style="color: #ff0000;">&quot;AUDIT_DATE&quot;</span> DATE <span style="color: #993333; font-weight: bold;">DEFAULT</span> SYSTIMESTAMP <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span>
<span style="color: #66cc66;">&#41;</span>;</pre></td></tr></table></div>


<p>Finally, we create the trigger to keep a log of changes to our original table.</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
</pre></td><td class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">OR</span> <span style="color: #993333; font-weight: bold;">REPLACE</span> <span style="color: #993333; font-weight: bold;">TRIGGER</span> <span style="color: #ff0000;">&quot;TA_COMMENT&quot;</span> 
before <span style="color: #993333; font-weight: bold;">UPDATE</span> <span style="color: #993333; font-weight: bold;">OR</span> <span style="color: #993333; font-weight: bold;">DELETE</span> <span style="color: #993333; font-weight: bold;">ON</span> COMMENT <span style="color: #993333; font-weight: bold;">FOR</span> each row
begin
<span style="color: #993333; font-weight: bold;">IF</span> deleting <span style="color: #993333; font-weight: bold;">OR</span> updating then 
  <span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> comment_audit<span style="color: #66cc66;">&#40;</span>
    COMMENT_ID<span style="color: #66cc66;">,</span>
    COMMENT_BODY<span style="color: #66cc66;">,</span>
    USER<span style="color: #66cc66;">,</span>
    CREATED_DATE
  <span style="color: #66cc66;">&#41;</span>
  <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span>
    :old<span style="color: #66cc66;">.</span>COMMENT_ID<span style="color: #66cc66;">,</span>
    :old<span style="color: #66cc66;">.</span>COMMENT_BODY<span style="color: #66cc66;">,</span>
    :old<span style="color: #66cc66;">.</span>USER<span style="color: #66cc66;">,</span>
    :old<span style="color: #66cc66;">.</span>CREATED_DATE
  <span style="color: #66cc66;">&#41;</span>;
end <span style="color: #993333; font-weight: bold;">IF</span>;
end;
<span style="color: #66cc66;">/</span>
<span style="color: #993333; font-weight: bold;">ALTER</span> <span style="color: #993333; font-weight: bold;">TRIGGER</span> <span style="color: #ff0000;">&quot;TA_COMMENT&quot;</span> ENABLE;</pre></td></tr></table></div>


<p>Now whenever a delete or update action is performed on the &#8220;COMMENT&#8221; table, a record of the old values and the date/time at which they were changed is recorded in the audit table.</p>

<div class="footnotes">
<hr />
<ol>

<li id="fn:1">
<p>The audit table is exactly the same as the table that we wish to keep a log of, except for one extra column, &#8220;AUDIT_DATE&#8221;, this will keep record the date/time of when an change occurred on the original table.&#160;<a href="#fnref:1" rev="footnote">&#8617;</a></p>
</li>

</ol>
</div>
]]></content:encoded>
			<wfw:commentRss>http://hocuspokus.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fhocuspokus.net%2F2007%2F10%2Flogaudit-tables-in-oracle&amp;seed_title=Log%2FAudit+Tables+in%26%23160%3BOracle/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Auto-Increment ID&#8217;s in&#160;Oracle</title>
		<link>http://hocuspokus.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fhocuspokus.net%2F2007%2F10%2Fauto-increment-ids-in-oracle&amp;seed_title=Auto-Increment+ID%26%238217%3Bs+in%26%23160%3BOracle</link>
		<comments>http://hocuspokus.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fhocuspokus.net%2F2007%2F10%2Fauto-increment-ids-in-oracle&amp;seed_title=Auto-Increment+ID%26%238217%3Bs+in%26%23160%3BOracle#comments</comments>
		<pubDate>Thu, 04 Oct 2007 11:39:06 +0000</pubDate>
		<dc:creator>Daz</dc:creator>
				<category><![CDATA[noteworthy]]></category>
		<category><![CDATA[oracle]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://hocuspokus.net/2007/10/04/auto-increment-ids-in-oracle/</guid>
		<description><![CDATA[This is old news to most people who have been using Oracle for a while, but to me this is something new that I learnt today.  How to have MySQL like &#8220;auto-increment&#8221; id&#8217;s for your tables in Oracle.   Here&#8217;s an example&#8230;



First we need to create a sequence for the ID&#8217;s:


1
2
3
4
CREATE SEQUENCE &#34;S_COMMENT_ID&#34;
START [...]]]></description>
			<content:encoded><![CDATA[<p>This is old news to most people who have been using Oracle for a while, but to me this is something new that I learnt today.  How to have MySQL like &#8220;auto-increment&#8221; id&#8217;s for your tables in Oracle. <img src='http://hocuspokus.net/wp-content/plugins/smilies-themer/tango/face-smile.png' alt=':)' class='wp-smiley' />  Here&#8217;s an example&#8230;</p>

<p><span id="more-22"></span></p>

<p>First we need to create a sequence for the ID&#8217;s:</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">CREATE</span> SEQUENCE <span style="color: #ff0000;">&quot;S_COMMENT_ID&quot;</span>
START <span style="color: #993333; font-weight: bold;">WITH</span> <span style="color: #cc66cc;">1</span>
INCREMENT <span style="color: #993333; font-weight: bold;">BY</span> <span style="color: #cc66cc;">1</span>
CACHE <span style="color: #cc66cc;">10</span>;</pre></td></tr></table></div>


<p>Then we create the table and the required trigger:</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
</pre></td><td class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> <span style="color: #ff0000;">&quot;COMMENT&quot;</span> <span style="color: #66cc66;">&#40;</span>
  <span style="color: #ff0000;">&quot;COMMENT_ID&quot;</span> NUMBER<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">10</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span> 
  <span style="color: #ff0000;">&quot;COMMENT_BODY&quot;</span> VARCHAR2<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1000</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> 
  <span style="color: #ff0000;">&quot;USER&quot;</span> VARCHAR2<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">100</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> 
  <span style="color: #ff0000;">&quot;CREATED_DATE&quot;</span> DATE<span style="color: #66cc66;">,</span> 
  CONSTRAINT <span style="color: #ff0000;">&quot;PK_COMMENT&quot;</span> <span style="color: #993333; font-weight: bold;">PRIMARY</span> <span style="color: #993333; font-weight: bold;">KEY</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;COMMENT_ID&quot;</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">OR</span> <span style="color: #993333; font-weight: bold;">REPLACE</span> <span style="color: #993333; font-weight: bold;">TRIGGER</span> <span style="color: #ff0000;">&quot;TR_COMMENT_ID&quot;</span> 
BEFORE <span style="color: #993333; font-weight: bold;">INSERT</span> 
<span style="color: #993333; font-weight: bold;">ON</span> COMMENT 
REFERENCING NEW <span style="color: #993333; font-weight: bold;">AS</span> NEW OLD <span style="color: #993333; font-weight: bold;">AS</span> OLD 
<span style="color: #993333; font-weight: bold;">FOR</span> EACH ROW 
BEGIN 
  <span style="color: #993333; font-weight: bold;">IF</span><span style="color: #66cc66;">&#40;</span>:new<span style="color: #66cc66;">.</span>comment_id <span style="color: #993333; font-weight: bold;">IS</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">&#41;</span> then 
  <span style="color: #993333; font-weight: bold;">SELECT</span> S_COMMENT_ID<span style="color: #66cc66;">.</span><span style="color: #993333; font-weight: bold;">NEXTVAL</span> 
  <span style="color: #993333; font-weight: bold;">INTO</span> :new<span style="color: #66cc66;">.</span>COMMENT_ID 
  <span style="color: #993333; font-weight: bold;">FROM</span> dual; 
  end <span style="color: #993333; font-weight: bold;">IF</span>; 
END;
<span style="color: #66cc66;">/</span>
<span style="color: #993333; font-weight: bold;">ALTER</span> <span style="color: #993333; font-weight: bold;">TRIGGER</span> <span style="color: #ff0000;">&quot;TR_COMMENT_ID&quot;</span> ENABLE;</pre></td></tr></table></div>


<p>And there you go - an auto-incrementing primary key&#8230;  Damn that&#8217;s a lot more code to write than a simple &#8216;auto-increment&#8217;.</p>

<p><em>Edit:</em> An alternative when using <a href="http://www.oracle.com/technology/software/products/sql/index.html">SQL Developer</a> is to create your table, select it, then go to the &#8216;Triggers&#8217; tab.  In there you will find a useful &#8216;Actions&#8230;&#8217; button where you can create a new trigger linking your tables primary key to a sequence.</p>
]]></content:encoded>
			<wfw:commentRss>http://hocuspokus.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fhocuspokus.net%2F2007%2F10%2Fauto-increment-ids-in-oracle&amp;seed_title=Auto-Increment+ID%26%238217%3Bs+in%26%23160%3BOracle/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->