Thanks Thomas. This is good idea to work around single table problem and MERGE command, but it will not work in this case. I am not updating anything, only returning key if record exists. Inserting otherwise. Regards, Ranko.
On 9/29/05, Mercadante, Thomas F (LABOR) < Thomas.Mercadante@(protected)> wrote: > > Ronko, > > Could you union all of the selects into one query and then use merge? > > Merge (table) > > Using > > select descr1 > > from lkp_table1 where cd = p_cd1 > > union > > select descr2 > > from lkp_table2 where cd = p_cd2 etc > > > > etc??? > > > > Would this work? > > Tom > > -- ---- ---- ---- ---- ---- -- > > *From:* oracle-l-bounce@(protected) [mailto: > oracle-l-bounce@(protected)] *On Behalf Of *Ranko Mosic > *Sent:* Thursday, September 29, 2005 8:45 AM > *To:* Paul Drake > *Cc:* ORACLE-L > *Subject:* Re: Dimension table load - PLSQL question > > Thanks for very helpful, no patronizing answer. If you've read more > carefully what the problem is > > you'd see that MERGE can't work because it works on one table upserting > another. > > I have one table being inserted from 6 tables. > > Thanks genius. > > On 9/28/05, *Paul Drake* <bdbafh@(protected)> wrote: > > On 9/28/05, *Ranko Mosic* <ranko.mosic@(protected) > wrote: > > Hi, > > requirement: > > - input parameters are codes p_cd1, p_cd2, ... > > - for these codes I get descriptions ( select descr1 into v_descr1 from > > > > lkp_table1 where cd = p_cd1; select descr2 into v_descr2 from lkp_table2 where > > > > cd = p_cd2 etc ) > > - check if table t has records where t.descr1 = v_descr1 > > and t.descr2 = v_descr2 and on and on ....; > > - if row exists return primary key; > > - if not then insert. > > > What is the best way of doing it ( simplest ) ? > > > > > Regards, Ranko. > > > > Ranko, > > "Simplest way" is to solicit opinions without using a search engine or > checking the documentation. > Its also usually "simplest" to leverage the existing provided > functionality, rather than writing your own routines, error handling, etc. > > A search of "oracle 10.1 upsert" in google.com <http://google.com/> + "I'm > feeling lucky" produced this for me. > Perhaps you might get lucky too. > > Paul > > http://www.psoug.org/reference/merge.html > > MERGE <hint> INTO <table_name> > USING <table_view_or_query> > ON (<condition>) > WHEN MATCHED THEN <update_clause> > WHEN NOT MATCHED THEN <insert_clause>; > >
<div>Thanks Thomas. This is good idea to work around single table problem and MERGE command, but it will not work in this case. </div> <div>I am not updating anything, only returning key if record exists. Inserting otherwise.</div> <div> </div> <div>Regards, Ranko.<br><br> </div> <div><span class="gmail_quote">On 9/29/05, <b class="gmail_sendername" >Mercadante, Thomas F (LABOR)</b> <<a href="mailto:Thomas.Mercadante@(protected) .state.ny.us">Thomas.Mercadante@(protected)</a>> wrote:</span> <blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0 .8ex; BORDER-LEFT: #ccc 1px solid"> <div> <p><font face="Arial" color="navy" size="2"><span style="FONT-SIZE: 10pt; COLOR : navy; FONT-FAMILY: Arial">Ronko,</span></font></p> <p><font face="Arial" color="navy" size="2"><span style="FONT-SIZE: 10pt; COLOR : navy; FONT-FAMILY: Arial"> </span></font></p> <p><font face="Arial" color="navy" size="2"><span style="FONT-SIZE: 10pt; COLOR : navy; FONT-FAMILY: Arial">Could you union all of the selects into one query and then use merge?</span></font></p> <p><font face="Arial" color="navy" size="2"><span style="FONT-SIZE: 10pt; COLOR : navy; FONT-FAMILY: Arial"> </span></font></p> <p><font face="Arial" color="navy" size="2"><span style="FONT-SIZE: 10pt; COLOR : navy; FONT-FAMILY: Arial">Merge (table)</span></font></p> <p><font face="Arial" color="navy" size="2"><span style="FONT-SIZE: 10pt; COLOR : navy; FONT-FAMILY: Arial"> Using</span></font></p><pre><font face="Arial " color="navy" size="2"><span style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial"> </span></font>select descr1 </pre><span class="q "><pre><font face="Courier New" size="2"><span style="FONT-SIZE: 10pt"> from lkp_table1 where cd = p_cd1</span></font></pre></span> <pre><font face="Courier New" size="2"> <span style="FONT-SIZE: 10pt"> union</span></font></pre><pre><font face="Courier New" size="2"><span style="FONT-SIZE: 10pt"> select descr2 </span></font></pre><span class="q"><pre><font face="Courier New" size= "2"><span style="FONT-SIZE: 10pt"> from lkp_table2 where cd = p_cd2 etc <br> <br> </span></font></pre><pre><font face="Courier New" size="2"><span style="FONT -SIZE: 10pt"> </span></font></pre></span><pre><font face="Courier New" size ="2"><span style="FONT-SIZE: 10pt">etc???</span></font></pre><pre><font face= "Courier New" size="2"> <span style="FONT-SIZE: 10pt"> </span></font></pre><pre><font face= "Courier New" size="2"><span style="FONT-SIZE: 10pt">Would this work?</span>< /font><font face="Arial" color="navy"><span style="COLOR: navy; FONT-FAMILY: Arial"> </span></font></pre> <p><font face="Arial" color="navy" size="2"><span style="FONT-SIZE: 10pt; COLOR : navy; FONT-FAMILY: Arial"> </span></font></p> <p><font face="Arial" color="navy" size="2"><span style="FONT-SIZE: 10pt; COLOR : navy; FONT-FAMILY: Arial">Tom</span></font></p> <p><font face="Arial" color="navy" size="2"><span style="FONT-SIZE: 10pt; COLOR : navy; FONT-FAMILY: Arial"> </span></font></p> <div> <div style="TEXT-ALIGN: center" align="center"><font face="Times New Roman" size="3"><span style="FONT-SIZE: 12pt"> <hr align="center" width="100%" size="2"> </span></font></div> <p><b><font face="Tahoma" size="2"><span style="FONT-WEIGHT: bold; FONT-SIZE: 10pt; FONT-FAMILY: Tahoma">From:</span></font></b><font face="Tahoma" size="2"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: Tahoma"> <a onclick="return top.js .OpenExtLink(window,event,this)" href="mailto:oracle-l-bounce@(protected)" target="_blank"> oracle-l-bounce@(protected)</a> [mailto:<a onclick="return top.js.OpenExtLink (window,event,this)" href="mailto:oracle-l-bounce@(protected)" target="_blank" >oracle-l-bounce@(protected)</a>] <b><span style="FONT-WEIGHT: bold"> On Behalf Of </span></b>Ranko Mosic<br><b><span style="FONT-WEIGHT: bold">Sent: </span></b> Thursday, September 29, 2005 8:45 AM<br><b><span style="FONT-WEIGHT: bold">To:</span></b> Paul Drake<br><b><span style="FONT-WEIGHT: bold"> Cc:</span></b> ORACLE-L<br><b><span style="FONT-WEIGHT: bold">Subject:</span>< /b> Re: Dimension table load - PLSQL question</span></font></p></div> <div><span class="e" id="q_106a1f854b800076_5"> <p><font face="Times New Roman" size="3"><span style="FONT-SIZE: 12pt"> < /span></font></p> <div> <p><font face="Times New Roman" size="3"><span style="FONT-SIZE: 12pt">Thanks for very helpful, no patronizing answer. If you've read more carefully what the problem is</span></font></p></div> <div> <p><font face="Times New Roman" size="3"><span style="FONT-SIZE: 12pt">you'd see that MERGE can't work because it works on one table upserting another. < /span></font></p></div> <div> <p><font face="Times New Roman" size="3"><span style="FONT-SIZE: 12pt">I have one table being inserted from 6 tables. </span></font></p></div> <div> <p><font face="Times New Roman" size="3"><span style="FONT-SIZE: 12pt">Thanks genius.<br><br> </span></font></p></div> <div> <p><span><font face="Times New Roman" size="3"><span style="FONT-SIZE: 12pt">On 9/28/05, <b><span style="FONT-WEIGHT: bold">Paul Drake</span></b> <<a onclick="return top.js.OpenExtLink(window,event,this)" href="mailto:bdbafh @(protected)" target="_blank"> bdbafh@(protected)</a>> wrote:</span></font></span> </p> <div><span> <p><span><font face="Times New Roman" size="3"><span style="FONT-SIZE: 12pt">On 9/28/05, <b><span style="FONT-WEIGHT: bold">Ranko Mosic</span></b> <<a onclick="return top.js.OpenExtLink(window,event,this)" href="mailto:ranko.mosic @(protected)" target="_blank"> ranko.mosic@(protected) </a>> wrote: </span></font></span></p> <div> <blockquote style="BORDER-RIGHT: medium none; PADDING-RIGHT: 0in; BORDER-TOP: medium none; PADDING-LEFT: 6pt; PADDING-BOTTOM: 0in; MARGIN-LEFT: 4.8pt; BORDER -LEFT: #cccccc 1pt solid; MARGIN-RIGHT: 0in; PADDING-TOP: 0in; BORDER-BOTTOM: medium none"> <pre><font face="Courier New" size="2"><span style="FONT-SIZE: 10pt">Hi, <br> requirement: <br> - input parameters are codes p_cd1, p_cd2, ...<br> - for these codes I get descriptions ( select descr1 into v_descr1 from </span> </font></pre><pre><font face="Courier New" size="2"><span style="FONT-SIZE: 10pt "><br> lkp_table1 where cd = p_cd1; select descr2 into v_descr2 from lkp_table2 where </span></font></pre><pre><font face="Courier New" size="2"><span style="FONT -SIZE: 10pt"><br> cd = p_cd2 etc )<br> - check if table t has records where t.descr1 = v_descr1<br> and t.descr2 = v_descr2 and on and on ....; <br> - if row exists return primary key; <br> - if not then insert. <br> <br> What is the best way of doing it ( simplest ) ? </span></font></pre><pre><font face="Courier New" size="2"><span style="FONT-SIZE: 10pt"><br> <br> Regards, Ranko. </span></font></pre> <p><font face="Times New Roman" size="3"><span style="FONT-SIZE: 12pt"> < /span></font></p></blockquote></div> <p><font face="Times New Roman" size="3"><span style="FONT-SIZE: 12pt"><br><br> </span></font></p></span></div> <p style="MARGIN-BOTTOM: 12pt"><font face="Times New Roman" size="3"><span style="FONT-SIZE: 12pt">Ranko,<br><br>"Simplest way" is to solicit opinions without using a search engine or checking the documentation. <br>Its also usually "simplest" to leverage the existing provided functionality, rather than writing your own routines, error handling, etc. <br> <br>A search of "oracle 10.1 upsert" in <a onclick="return top.js .OpenExtLink(window,event,this)" href="http://google.com/" target="_blank"> google.com</a> + "I'm feeling lucky" produced this for me. <br >Perhaps you might get lucky too.<br><br>Paul<br><br><a onclick="return top.js .OpenExtLink(window,event,this)" href="http://www.psoug.org/reference/merge.html " target="_blank"> http://www.psoug.org/reference/merge.html</a> </span></font></p> <table style="BACKGROUND: #d8d8c4; WIDTH: 90%" cellpadding="0" width="90%" bgcolor="#d8d8c4" border="1"> <tbody> <tr> <td style="PADDING-RIGHT: 0.75pt; PADDING-LEFT: 0.75pt; PADDING-BOTTOM: 0.75pt; WIDTH: 25%; PADDING-TOP: 0.75pt" width="25%" rowspan="2"> <p><font face="Times New Roman" size="3"><span style="FONT-SIZE: 12pt"> < /span></font></p></td> <td style="PADDING-RIGHT: 0.75pt; PADDING-LEFT: 0.75pt; PADDING-BOTTOM: 0.75pt; WIDTH: 75%; PADDING-TOP: 0.75pt" width="75%"> <p><font face="Courier" size="3"><span style="FONT-SIZE: 12pt; FONT-FAMILY: Courier">MERGE <hint> INTO <table_name><br>USING <table_view_or _query><br>ON (<condition>)<br>WHEN MATCHED THEN <update_clause> <br>WHEN NOT MATCHED THEN <insert_clause>; </span></font></p></td> <td style="BORDER-RIGHT: medium none; BORDER-TOP: medium none; BORDER-LEFT: medium none; BORDER-BOTTOM: medium none" width="0"> <p> </p></td></tr> <tr height="19"> <td style="BORDER-RIGHT: medium none; PADDING-RIGHT: 0in; BORDER-TOP: medium none; PADDING-LEFT: 0in; PADDING-BOTTOM: 0in; BORDER-LEFT: medium none; PADDING -TOP: 0in; BORDER-BOTTOM: medium none" width="386"> <p> </p></td> <td style="BORDER-RIGHT: medium none; BORDER-TOP: medium none; BORDER-LEFT: medium none; BORDER-BOTTOM: medium none" width="0" height="19"></td></tr>< /tbody></table> <p><font face="Times New Roman" size="3"><span style="FONT-SIZE: 12pt"> < /span></font></p></div> <p><font face="Times New Roman" size="3"><span style="FONT-SIZE: 12pt"> < /span></font></p></span></div></div></blockquote></div><br>