<?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>MacLochlainns Weblog &#187; WHERE CURRENT IS</title>
	<atom:link href="http://blog.mclaughlinsoftware.com/tag/where-current-is/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.mclaughlinsoftware.com</link>
	<description>Michael McLaughlin's Technical Blog</description>
	<lastBuildDate>Mon, 06 Sep 2010 21:21:48 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>The FOR UPDATE and WHERE CURRENT OF statements</title>
		<link>http://blog.mclaughlinsoftware.com/2008/08/24/the-for-update-and-where-current-of-statements/</link>
		<comments>http://blog.mclaughlinsoftware.com/2008/08/24/the-for-update-and-where-current-of-statements/#comments</comments>
		<pubDate>Sun, 24 Aug 2008 17:47:06 +0000</pubDate>
		<dc:creator>maclochlainn</dc:creator>
				<category><![CDATA[Oracle]]></category>
		<category><![CDATA[pl/sql]]></category>
		<category><![CDATA[BULK SQL]]></category>
		<category><![CDATA[DELETE WHERE CURRENT OF]]></category>
		<category><![CDATA[FOR UPDATE]]></category>
		<category><![CDATA[UPDATE WHERE CURRENT OF]]></category>
		<category><![CDATA[WHERE CURRENT IS]]></category>
		<category><![CDATA[WHERE CURRENT OF]]></category>

		<guid isPermaLink="false">http://maclochlainn.wordpress.com/?p=279</guid>
		<description><![CDATA[The FOR UPDATE clause has been part of Oracle SQL for years. As part of SQLJ, they introduced the WHERE CURRENT OF clause in Oracle 10g. The WHERE CURRENT OF clause allows you to join on ROWIDs the cursor and an UPDATE or DELETE statement in a loop. For example, you can do something like [...]]]></description>
			<content:encoded><![CDATA[<p>The <code>FOR UPDATE</code> clause has been part of Oracle SQL for years. As part of SQLJ, they introduced the <code>WHERE CURRENT OF</code> clause in Oracle 10g. The <code>WHERE CURRENT OF</code> clause allows you to join on <code>ROWID</code>s the cursor and an <code>UPDATE</code> or <code>DELETE</code> statement in a loop.</p>
<p>For example, you can do something like this:</p>
<p><img class="aligncenter size-full wp-image-280" src="http://blog.mclaughlinsoftware.com/wp-content/uploads/2008/08/wherecurrentof.jpg" alt="" style="border:none" width="430" height="209" /></p>
<p>Alternatively, you can wrap this in a bulk operation (that doesn&#8217;t do anything really because it&#8217;s the same table), like this:</p>
<p><img class="aligncenter size-full wp-image-283" src="http://blog.mclaughlinsoftware.com/wp-content/uploads/2008/08/bulkwherecurrentof1.jpg" alt="" style="border:none" width="589" height="341" /></p>
<p>I have to ask why you don&#8217;t simply write a correlated <code>UPDATE</code> or <code>DELETE</code> statement, like this:</p>

<div class="wp_syntax"><div class="code"><pre class="plsql" style="font-family:monospace;"><span style="color: #00F;">UPDATE</span>   item i1
<span style="color: #00F;">SET</span>      last_updated_by <span style="color: #00F;">=</span> <span style="color: #800;">3</span>
<span style="color: #00F;">,</span>        last_update_date <span style="color: #00F;">=</span> <span style="color: #000;">TRUNC</span><span style="color: #00F;">&#40;</span><span style="color: #000;">SYSDATE</span><span style="color: #00F;">&#41;</span>
<span style="color: #00F;">WHERE</span>    <span style="color: #00F;">EXISTS</span> <span style="color: #00F;">&#40;</span><span style="color: #00F;">SELECT</span> <span style="color: #00F;">NULL</span>
                 <span style="color: #00F;">FROM</span>    item i2
                 <span style="color: #00F;">WHERE</span>   i2<span style="color: #00F;">.</span>item_id <span style="color: #00F;">BETWEEN</span> <span style="color: #800;">1031</span> <span style="color: #00F;">AND</span> <span style="color: #800;">1040</span>
                 <span style="color: #00F;">AND</span>     i1<span style="color: #00F;">.</span><span style="color: #00F;">ROWID</span> <span style="color: #00F;">=</span> i2<span style="color: #00F;">.</span><span style="color: #00F;">ROWID</span><span style="color: #00F;">&#41;</span><span style="color: #00F;">;</span></pre></div></div>

<p>There hasn&#8217;t been time to run any tuning diagnostics on this but perhaps it should go into the queue of what-ifs. Any thoughts are welcome &#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.mclaughlinsoftware.com/2008/08/24/the-for-update-and-where-current-of-statements/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
