<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: SQL &#8211; Programmatic Row By Row to MERGE INTO</title>
	<atom:link href="http://hoopercharles.wordpress.com/2010/07/27/sql-programmatic-row-by-row-to-merge-into/feed/" rel="self" type="application/rss+xml" />
	<link>http://hoopercharles.wordpress.com/2010/07/27/sql-programmatic-row-by-row-to-merge-into/</link>
	<description>Miscellaneous Random Oracle Topics: Stop, Think, ... Understand</description>
	<lastBuildDate>Mon, 13 May 2013 14:10:06 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
	<item>
		<title>By: Charles Hooper</title>
		<link>http://hoopercharles.wordpress.com/2010/07/27/sql-programmatic-row-by-row-to-merge-into/#comment-1580</link>
		<dc:creator><![CDATA[Charles Hooper]]></dc:creator>
		<pubDate>Wed, 28 Jul 2010 17:31:39 +0000</pubDate>
		<guid isPermaLink="false">http://hoopercharles.wordpress.com/?p=2870#comment-1580</guid>
		<description><![CDATA[Jimmy and Joel,

Thank you for adding additional information to the blog article.  Based on your comments, it appears that there are a couple of landminds lurking just below the surface of the MERGE INTO command.  Some of the landminds are included in the 11g R2 documentation reference that was included at the end of the blog article.

---

Jimmy, could you explain a little more about &quot;we have to use UPSERTS&quot; - I am having trouble finding anything in the Oracle documentation other than the MERGE INTO syntax for performing an UPSERT.  I found the following two references that mention UPSERTS:
http://download.oracle.com/docs/cd/E11882_01/server.112/e10810/sqlmodel.htm#DWHSG8790
http://download.oracle.com/docs/cd/E11882_01/server.112/e10592/statements_10002.htm#SQLRF55348

---

It appears that I left out at least one code sample.  Prior to the first code sample there should be a code sample that performs a select statement in a loop, followed by an INSERT or UPDATE statement in the same loop, using hard-coded literals, of course.  The FOR loop would look something like this:
[code]
For i = 1 To 30
    strSQL = &quot;SELECT&quot; &amp; vbCrLf
    strSQL = strSQL &amp; &quot;  ID,&quot; &amp; vbCrLf
    strSQL = strSQL &amp; &quot;  COL2,&quot; &amp; vbCrLf
    strSQL = strSQL &amp; &quot;  COL3,&quot; &amp; vbCrLf
    strSQL = strSQL &amp; &quot;  COL4&quot; &amp; vbCrLf
    strSQL = strSQL &amp; &quot;FROM&quot; &amp; vbCrLf
    strSQL = strSQL &amp; &quot;  T2&quot; &amp; vbCrLf
    strSQL = strSQL &amp; &quot;WHERE&quot; &amp; vbCrLf
    strSQL = strSQL &amp; &quot;  ID=&quot; &amp; CStr(i)
 
    snpData.Open strSQL, dbDatabase
 
    intS_ID = i
    intS_C2 = Int(Rnd * 1000) + 1
    intS_C3 = Int(Rnd * 1000) + 1
    intS_C4 = Int(Rnd * 1000) + 1
 
    If Not (snpData.BOF And snpData.EOF) Then
        strSQL = &quot;UPDATE&quot; &amp; vbCrLf
        strSQL = strSQL &amp; &quot;  T2&quot; &amp; vbCrLf
        strSQL = strSQL &amp; &quot;SET&quot; &amp; vbCrLf
        strSQL = strSQL &amp; &quot;  COL2=0,&quot; &amp; vbCrLf
        strSQL = strSQL &amp; &quot;  COL3=&quot; &amp; cStr(cLng(snpData(&quot;col2&quot;)) + cLng(snpData(&quot;col3&quot;))) &amp; &quot;,&quot; &amp; vbCrLf
        strSQL = strSQL &amp; &quot;  COL4=&quot; &amp; cStr(intS_C4) &amp; vbCrLf
        strSQL = strSQL &amp; &quot;WHERE&quot; &amp; vbCrLf
        strSQL = strSQL &amp; &quot;  ID=&quot; &amp; cStr(i)
 
        dbDatabase.Execute strSQL
    Else
        &#039;No row found, need to add
        strSQL = &quot;INSERT INTO&quot; &amp; vbCrLf
        strSQL = strSQL &amp; &quot;  T2&quot; &amp; vbCrLf
        strSQL = strSQL &amp; &quot;VALUES(&quot; &amp; vbCrLf
        strSQL = strSQL &amp; &quot;  &quot; &amp; cStr(i) &amp; &quot;,&quot; &amp; vbCrLf
        strSQL = strSQL &amp; &quot;  &quot; &amp; cStr(intS_C2) &amp; &quot;,&quot; &amp; vbCrLf
        strSQL = strSQL &amp; &quot;  &quot; &amp; cStr(intS_C3) &amp; &quot;,&quot; &amp; vbCrLf
        strSQL = strSQL &amp; &quot;  &quot; &amp; cStr(intS_C4) &amp; &quot;)&quot; &amp; vbCrLf
 
        dbDatabase.Execute strSQL
    End If

    snpData.Close
Next
[/code]]]></description>
		<content:encoded><![CDATA[<p>Jimmy and Joel,</p>
<p>Thank you for adding additional information to the blog article.  Based on your comments, it appears that there are a couple of landminds lurking just below the surface of the MERGE INTO command.  Some of the landminds are included in the 11g R2 documentation reference that was included at the end of the blog article.</p>
<p>&#8212;</p>
<p>Jimmy, could you explain a little more about &#8220;we have to use UPSERTS&#8221; &#8211; I am having trouble finding anything in the Oracle documentation other than the MERGE INTO syntax for performing an UPSERT.  I found the following two references that mention UPSERTS:<br />
<a href="http://download.oracle.com/docs/cd/E11882_01/server.112/e10810/sqlmodel.htm#DWHSG8790" rel="nofollow">http://download.oracle.com/docs/cd/E11882_01/server.112/e10810/sqlmodel.htm#DWHSG8790</a><br />
<a href="http://download.oracle.com/docs/cd/E11882_01/server.112/e10592/statements_10002.htm#SQLRF55348" rel="nofollow">http://download.oracle.com/docs/cd/E11882_01/server.112/e10592/statements_10002.htm#SQLRF55348</a></p>
<p>&#8212;</p>
<p>It appears that I left out at least one code sample.  Prior to the first code sample there should be a code sample that performs a select statement in a loop, followed by an INSERT or UPDATE statement in the same loop, using hard-coded literals, of course.  The FOR loop would look something like this:</p>
<pre class="brush: plain; title: ; notranslate">
For i = 1 To 30
    strSQL = &quot;SELECT&quot; &amp; vbCrLf
    strSQL = strSQL &amp; &quot;  ID,&quot; &amp; vbCrLf
    strSQL = strSQL &amp; &quot;  COL2,&quot; &amp; vbCrLf
    strSQL = strSQL &amp; &quot;  COL3,&quot; &amp; vbCrLf
    strSQL = strSQL &amp; &quot;  COL4&quot; &amp; vbCrLf
    strSQL = strSQL &amp; &quot;FROM&quot; &amp; vbCrLf
    strSQL = strSQL &amp; &quot;  T2&quot; &amp; vbCrLf
    strSQL = strSQL &amp; &quot;WHERE&quot; &amp; vbCrLf
    strSQL = strSQL &amp; &quot;  ID=&quot; &amp; CStr(i)
 
    snpData.Open strSQL, dbDatabase
 
    intS_ID = i
    intS_C2 = Int(Rnd * 1000) + 1
    intS_C3 = Int(Rnd * 1000) + 1
    intS_C4 = Int(Rnd * 1000) + 1
 
    If Not (snpData.BOF And snpData.EOF) Then
        strSQL = &quot;UPDATE&quot; &amp; vbCrLf
        strSQL = strSQL &amp; &quot;  T2&quot; &amp; vbCrLf
        strSQL = strSQL &amp; &quot;SET&quot; &amp; vbCrLf
        strSQL = strSQL &amp; &quot;  COL2=0,&quot; &amp; vbCrLf
        strSQL = strSQL &amp; &quot;  COL3=&quot; &amp; cStr(cLng(snpData(&quot;col2&quot;)) + cLng(snpData(&quot;col3&quot;))) &amp; &quot;,&quot; &amp; vbCrLf
        strSQL = strSQL &amp; &quot;  COL4=&quot; &amp; cStr(intS_C4) &amp; vbCrLf
        strSQL = strSQL &amp; &quot;WHERE&quot; &amp; vbCrLf
        strSQL = strSQL &amp; &quot;  ID=&quot; &amp; cStr(i)
 
        dbDatabase.Execute strSQL
    Else
        'No row found, need to add
        strSQL = &quot;INSERT INTO&quot; &amp; vbCrLf
        strSQL = strSQL &amp; &quot;  T2&quot; &amp; vbCrLf
        strSQL = strSQL &amp; &quot;VALUES(&quot; &amp; vbCrLf
        strSQL = strSQL &amp; &quot;  &quot; &amp; cStr(i) &amp; &quot;,&quot; &amp; vbCrLf
        strSQL = strSQL &amp; &quot;  &quot; &amp; cStr(intS_C2) &amp; &quot;,&quot; &amp; vbCrLf
        strSQL = strSQL &amp; &quot;  &quot; &amp; cStr(intS_C3) &amp; &quot;,&quot; &amp; vbCrLf
        strSQL = strSQL &amp; &quot;  &quot; &amp; cStr(intS_C4) &amp; &quot;)&quot; &amp; vbCrLf
 
        dbDatabase.Execute strSQL
    End If

    snpData.Close
Next
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: joel garry</title>
		<link>http://hoopercharles.wordpress.com/2010/07/27/sql-programmatic-row-by-row-to-merge-into/#comment-1578</link>
		<dc:creator><![CDATA[joel garry]]></dc:creator>
		<pubDate>Tue, 27 Jul 2010 23:09:10 +0000</pubDate>
		<guid isPermaLink="false">http://hoopercharles.wordpress.com/?p=2870#comment-1578</guid>
		<description><![CDATA[I must add, the merge statement can be sensitive to the DDL environment, as well as the data.  There are &lt;a href=&quot;http://tkyte.blogspot.com/2010/04/something-i-recently-unlearned.html&quot; rel=&quot;nofollow&quot;&gt;possible locking issues&lt;/a&gt; and &lt;a href=&quot;http://www.oracle-base.com/articles/10g/DmlErrorLogging_10gR2.php&quot; rel=&quot;nofollow&quot;&gt; you have to carefully handle errors&lt;/a&gt;.  If you don&#039;t watch your data, a null in a key can blow off a whole load routine that had previously worked flawlessly.  (You can guess Cary&#039;s post directly applies to my experience with that!)

I notice Tom Kyte published &quot;My First Day with the New Release&quot; article five years ago, and said [LOG ERRORS] &quot; is destined to be my favorite new feature of Oracle Database 10g Release 2.&quot;]]></description>
		<content:encoded><![CDATA[<p>I must add, the merge statement can be sensitive to the DDL environment, as well as the data.  There are <a href="http://tkyte.blogspot.com/2010/04/something-i-recently-unlearned.html" rel="nofollow">possible locking issues</a> and <a href="http://www.oracle-base.com/articles/10g/DmlErrorLogging_10gR2.php" rel="nofollow"> you have to carefully handle errors</a>.  If you don&#8217;t watch your data, a null in a key can blow off a whole load routine that had previously worked flawlessly.  (You can guess Cary&#8217;s post directly applies to my experience with that!)</p>
<p>I notice Tom Kyte published &#8220;My First Day with the New Release&#8221; article five years ago, and said [LOG ERRORS] &#8221; is destined to be my favorite new feature of Oracle Database 10g Release 2.&#8221;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jimmy</title>
		<link>http://hoopercharles.wordpress.com/2010/07/27/sql-programmatic-row-by-row-to-merge-into/#comment-1577</link>
		<dc:creator><![CDATA[Jimmy]]></dc:creator>
		<pubDate>Tue, 27 Jul 2010 21:00:35 +0000</pubDate>
		<guid isPermaLink="false">http://hoopercharles.wordpress.com/?p=2870#comment-1577</guid>
		<description><![CDATA[Good stuff, Charles!

Where I work we can&#039;t use MERGE INTO statements, we have to use UPSERTS. We have VPD implemented which does not support the MERGE statement. You get ORA-28132 Merge into syntax does not support security policies.]]></description>
		<content:encoded><![CDATA[<p>Good stuff, Charles!</p>
<p>Where I work we can&#8217;t use MERGE INTO statements, we have to use UPSERTS. We have VPD implemented which does not support the MERGE statement. You get ORA-28132 Merge into syntax does not support security policies.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
