<?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>BorkWeb &#187; database</title>
	<atom:link href="http://borkweb.com/story/tag/database/feed" rel="self" type="application/rss+xml" />
	<link>http://borkweb.com</link>
	<description>Some People Are Squirrel Handed.</description>
	<lastBuildDate>Tue, 17 Jan 2012 22:00:21 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Oracle 10g: Using The Returning Clause With ADOdb</title>
		<link>http://borkweb.com/story/oracle-10g-using-the-returning-clause-with-adodb</link>
		<comments>http://borkweb.com/story/oracle-10g-using-the-returning-clause-with-adodb#comments</comments>
		<pubDate>Tue, 21 Oct 2008 13:26:49 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[10g]]></category>
		<category><![CDATA[adodb]]></category>
		<category><![CDATA[banner]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[dml]]></category>
		<category><![CDATA[oracle]]></category>
		<category><![CDATA[oracle 10g]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://borkweb.com/?p=638</guid>
		<description><![CDATA[Plymouth State University uses Oracle heavily due to its Student Information System of choice &#8211; SungardHE Banner. As such, I play around in Oracle a lot (sometimes a lot more than I&#8217;d like) and I occasionally find functionality that seems more cumbersome than it should. One such item is selecting the last inserted value on [...]]]></description>
			<content:encoded><![CDATA[<p>Plymouth State University uses <a href="http://www.oracle.com">Oracle</a> heavily due to its Student Information System of choice &#8211; <a href="http://www.sungardhe.com">SungardHE</a> Banner.  As such, I play around in Oracle a lot (sometimes a lot more than I&#8217;d like) and I occasionally find functionality that seems more cumbersome than it should.  </p>
<p>One such item is <strong>selecting the last inserted value on an auto-incrementing column</strong>.</p>
<p>Historically, when you are inserting into a table with auto incrementing values (via a <a href="http://borkweb.com/story/oracles-auto-incrementing-with-sequences">sequence</a>) you have always been able to grab the last value with a simple SELECT statement (line 22):</p>
<pre class="brush: sql; title: ; notranslate">
-- setup a table
CREATE TABLE bork (id INTEGER NOT NULL PRIMARY KEY, data VARCHAR2(10) NOT NULL);

-- create the sequence
CREATE SEQUENCE sq_bork INCREMENT BY 1 START WITH 1; 

-- create a trigger for auto-incrementing the sequence'
CREATE OR REPLACE TRIGGER tr_sq_bork
BEFORE INSERT
ON bork
REFERENCING NEW AS NEW
FOR EACH ROW
BEGIN
SELECT sq_bork.NEXTVAL INTO :NEW.id FROM DUAL;
END;
/

-- insert a record into the table
INSERT INTO bork (name) VALUES ('Matt');

-- retrieve last inserted id
SELECT sq_bork.CURRVAL FROM dual;
</pre>
<p>As you see there, two statements must be executed to get that new id.  The INSERT and the SELECT.  Well, as of Oracle 10g you can utilize the RETURNING clause like so:</p>
<pre class="brush: sql; title: ; notranslate">
INSERT INTO bork (name) VALUES ('Matt') RETURNING id INTO i_id;
</pre>
<p>That statement inserts a record into &#8220;bork&#8221; and returns the value of &#8220;id&#8221; into the &#8220;i_id&#8221; variable.  Pretty sexy and all with one DML statement.  Here&#8217;s what we do at Plymouth to utilize the RETURNING clause with the PHP library <a href="http://adodb.sf.net">ADOdb</a>:</p>
<pre class="brush: php; title: ; notranslate">
&lt; ?php
//do your database object initialization here:
//$db = new ADONewConnection...

$sql = &quot;BEGIN INSERT INTO bork (data) VALUES ('Matt') RETURNING id INTO :i_id; END;&quot;;
$stmt = $db-&gt;PrepareSP($sql);
$db-&gt;OutParameter($stmt, $inserted_id, 'i_id');
$db-&gt;Execute($stmt);
?&gt;
</pre>
<p>Yup.  4 lines of PHP but only 1 statement sent to the database!  I&#8217;d take the extra lines any day over the latency of data retrieval.</p>
]]></content:encoded>
			<wfw:commentRss>http://borkweb.com/story/oracle-10g-using-the-returning-clause-with-adodb/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Delete/Backspace Stops Working in Oracle SQLDeveloper</title>
		<link>http://borkweb.com/story/deletebackspace-stops-working-in-oracle-sqldeveloper</link>
		<comments>http://borkweb.com/story/deletebackspace-stops-working-in-oracle-sqldeveloper#comments</comments>
		<pubDate>Thu, 18 Sep 2008 12:00:17 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[accelerator]]></category>
		<category><![CDATA[backspace]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[delete]]></category>
		<category><![CDATA[key bindings]]></category>
		<category><![CDATA[oracle]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[sql developer]]></category>

		<guid isPermaLink="false">http://borkweb.com/?p=563</guid>
		<description><![CDATA[I a huge fan of Oracle SQL Developer but I ran into an issue a while back that left me scratching my head and re-installing. The issue? Most key strokes other than letters and numbers failed to function. Yeah&#8230;no delete or backspace. When this issue happened a second time I did a little playing with [...]]]></description>
			<content:encoded><![CDATA[<p>I a huge fan of <a href="http://www.oracle.com/technology/software/products/sql/index.html">Oracle SQL Developer</a> but I ran into an issue a while back that left me scratching my head and re-installing.  The issue?  Most key strokes other than letters and numbers failed to function.  Yeah&#8230;no delete or backspace.  </p>
<p>When this issue happened a second time I did a little playing with the app and figured out what to do.  If you find yourself in a similar predicament simply do this:</p>
<ol>
<li>Open SQL Developer</li>
<li>Click on the Tools &gt; Preferences menu</li>
<li>Click on Accelerators on the left</li>
<li>Click the Load Preset&#8230; button</li>
</ol>
<p>Yup.  That&#8217;s it.  The only lame part about that is all your custom key bindings go away and must be re-done.  But that is <strong>much</strong> nicer than re-installing!</p>
]]></content:encoded>
			<wfw:commentRss>http://borkweb.com/story/deletebackspace-stops-working-in-oracle-sqldeveloper/feed</wfw:commentRss>
		<slash:comments>38</slash:comments>
		</item>
		<item>
		<title>Compiling Invalid Objects in PL/SQL</title>
		<link>http://borkweb.com/story/compiling-invalid-objects-in-plsql</link>
		<comments>http://borkweb.com/story/compiling-invalid-objects-in-plsql#comments</comments>
		<pubDate>Wed, 25 Jun 2008 19:05:19 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[compile]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[invalid objects]]></category>
		<category><![CDATA[oracle]]></category>
		<category><![CDATA[plsql]]></category>

		<guid isPermaLink="false">http://borkweb.com/?p=559</guid>
		<description><![CDATA[While I do a lot of and prefer PHP and JavaScript development, my daily job has a darker side&#8230;PL/SQL. At times the packages that I oversee invalidate during upgrades or poor compilations of a package that ends up having a ripple effect. Here&#8217;s a query I wrote to find the invalid objects and generate compile [...]]]></description>
			<content:encoded><![CDATA[<p>While I do a lot of and prefer PHP and JavaScript development, my daily job has a darker side&#8230;PL/SQL.  At times the packages that I oversee invalidate during upgrades or poor compilations of a package that ends up having a ripple effect.  </p>
<p>Here&#8217;s a query I wrote to find the invalid objects and generate compile statements to attempt to fix whatever is busted.</p>
<pre class="brush: sql; title: ; notranslate">
SELECT CASE object_type
       WHEN 'PACKAGE' THEN
        'ALTER '||object_type||' '||owner||'.'||object_name||' COMPILE;'
       ELSE
        'ALTER PACKAGE '||owner||'.'||object_name||' COMPILE BODY;'
       END
  FROM dba_objects
 WHERE status = 'INVALID'
   AND object_type in ('PACKAGE','PACKAGE BODY','FUNCTION','PROCEDURE');
</pre>
]]></content:encoded>
			<wfw:commentRss>http://borkweb.com/story/compiling-invalid-objects-in-plsql/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Guest Lecture: Application Design with Databases</title>
		<link>http://borkweb.com/story/database-programming-talk</link>
		<comments>http://borkweb.com/story/database-programming-talk#comments</comments>
		<pubDate>Mon, 04 Dec 2006 20:43:28 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database programming]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[plymouth state university]]></category>
		<category><![CDATA[psu]]></category>

		<guid isPermaLink="false">http://borkweb.com/story/database-programming-talk</guid>
		<description><![CDATA[I had the privilege of being a guest speaker at Plymouth State University&#8217;s Database Management class. The focus of the lecture was regarding Web Application Design and how it relates to database integration. Here are the slides that were handed out and for those curious, here&#8217;s the topics of discussion: Topics: My Background My Project [...]]]></description>
			<content:encoded><![CDATA[<p>I had the privilege of being a guest speaker at <a href="http://www.plymouth.edu">Plymouth State University&#8217;s</a> Database Management class.  The focus of the lecture was regarding Web Application Design and how it relates to database integration.  Here are <a href="http://borkweb.com/downloads/database_talk.ppt">the slides</a> that were handed out and for those curious, here&#8217;s the topics of discussion:</p>
<p>Topics:</p>
<ul>
<li>My Background</li>
<li>My Project Background</li>
<li>Application Design Process
<ul>
<li>Analysis</li>
<li>Language Selection</li>
<li>Database Design</li>
<li>Interface Design</li>
<li>Development</li>
<li>The Sweet Stuff</li>
</ul>
</li>
<li>Industry
<ul>
<li>Where it was</li>
<li>Where it is</li>
<li>Where its going</li>
</ul>
</li>
<li>Stuff I&#8217;ve Learned</li>
<li>Suggestions</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://borkweb.com/story/database-programming-talk/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Oracle&#8217;s Auto Incrementing with Sequences</title>
		<link>http://borkweb.com/story/oracles-auto-incrementing-with-sequences</link>
		<comments>http://borkweb.com/story/oracles-auto-incrementing-with-sequences#comments</comments>
		<pubDate>Fri, 17 Feb 2006 15:50:36 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA["auto increment"]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[oracle]]></category>
		<category><![CDATA[sequences]]></category>
		<category><![CDATA[sequencing]]></category>

		<guid isPermaLink="false">http://www.borkweb.com/story/oracles-auto-incrementing-with-sequences</guid>
		<description><![CDATA[My previous post, titled: &#8216;Sequence-less/Trigger-less Oracle Auto Increment&#8216; was shot out of the water by my friend and DBA, Jon Emmons. Glad to see that I can be kept in line. So I have resigned to use Oracle Sequences as a safer means for auto incrementing. But that doesn&#8217;t mean that I like it. Here&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>My previous post, titled: &#8216;<a href="http://www.borkweb.com/story/sequence-lesstrigger-less-oracle-auto-increment">Sequence-less/Trigger-less Oracle Auto Increment</a>&#8216; was shot out of the water by my friend and DBA, <a href="http://www.lifeaftercoffee.com/2006/02/17/how-not-to-create-auto-increment-columns-in-oracle">Jon Emmons</a>.  Glad to see that I can be kept in line.</p>
<p>So I have resigned to use Oracle Sequences as a safer means for auto incrementing.  But that doesn&#8217;t mean that I like it.  Here&#8217;s what needs to be done to implement auto_incrementing with Oracle:</p>
<p>First, create a sequence:</p>
<blockquote><p>
CREATE SEQUENCE sweet_incrementing INCREMENT BY 1 START WITH 1;
</p></blockquote>
<p>Next write your statement:</p>
<blockquote><p>
INSERT INTO table (id,name) VALUES (sweet_incrementing.NextVal,&#8217;bork&#8217;);
</p></blockquote>
<p>Now at a second glance, this statement looks much cleaner than my first attempt at subverting the system.  However, the fact that you need to create a whole new sequence for each table you wish to have an auto incrementer is pretty stupid when compared to MySQL&#8217;s plan of attack.  In MySQL you can simply mark a column as a auto_increment during table creation and you&#8217;re good to go!</p>
]]></content:encoded>
			<wfw:commentRss>http://borkweb.com/story/oracles-auto-incrementing-with-sequences/feed</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>Sequence-less/Trigger-less Oracle Auto Increment</title>
		<link>http://borkweb.com/story/sequence-lesstrigger-less-oracle-auto-increment</link>
		<comments>http://borkweb.com/story/sequence-lesstrigger-less-oracle-auto-increment#comments</comments>
		<pubDate>Thu, 16 Feb 2006 21:50:05 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA["auto increment"]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[insert]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[oracle]]></category>

		<guid isPermaLink="false">http://www.borkweb.com/story/sequence-lesstrigger-less-oracle-auto-increment</guid>
		<description><![CDATA[Oracle sucks. Well, not totally, but it fails in a lot of places where MySQL is sexy. One little gem of an irritation is the lack of an auto_increment attribute associated with fields. Instead you have to make use of Oracle Sequences/Triggers which adds a whole layer of complexity on the creation and insertion into [...]]]></description>
			<content:encoded><![CDATA[<p>Oracle sucks.  Well, not totally, but it fails in a lot of places where MySQL is sexy.  One little gem of an irritation is the lack of an <strong>auto_increment</strong> attribute associated with fields.  Instead you have to make use of Oracle Sequences/Triggers which adds a whole layer of complexity on the creation and insertion into a simple table.</p>
<p>I&#8217;m not quite sure on this statement&#8217;s efficiency, but here&#8217;s my solution:</p>
<blockquote><p>INSERT INTO table (id,name) (SELECT CASE WHEN MAX(id) IS NULL THEN 1 ELSE MAX(id)+1 END, &#8216;bork&#8217; FROM table);</p></blockquote>
<p>EDIT: It seems that this isn&#8217;t such a good idea, after help from my <a href="http://www.lifeaftercoffee.com/2006/02/17/how-not-to-create-auto-increment-columns-in-oracle/">friendly neighborhood DBA</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://borkweb.com/story/sequence-lesstrigger-less-oracle-auto-increment/feed</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
	</channel>
</rss>

