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>;
<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size: 10.0pt;font-family:Arial;color:navy'>Could you union all of the selects into one query and then use merge?<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size: 12.0pt'><o:p> </o:p></span></font></p>
<div>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size: 12.0pt'>Thanks for very helpful, no patronizing answer. If you've read more carefully what the problem is<o:p></o:p></span></font></p>
</div>
<div>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size: 12.0pt'>you'd see that MERGE can't work because it works on one table upserting another. <o:p></o:p></span></font></p>
</div>
<div>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size: 12.0pt'>I have one table being inserted from 6 tables. <o:p></o:p></span></font ></p>
<blockquote style='border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt; margin-left:4.8pt;margin-right:0in'><pre><font size=2 face="Courier New"><span style='font-size:10.0pt'>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 <o:p>< /o:p></span></font></pre><pre><font size=2 face="Courier New"><span style='font-size:10.0pt'><br> lkp_table1 where cd = p_cd1; select descr2 into v_descr2 from lkp_table2 where <o:p></o:p></span></font></pre><pre><font size=2 face="Courier New"><span style='font-size:10.0pt'><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 ) ? <o:p></o:p></span></font></pre> <pre><font size=2 face="Courier New"><span style='font-size:10.0pt'><br> <br> Regards, Ranko. <o:p></o:p></span></font></pre>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size: 12.0pt'><o:p> </o:p></span></font></p>
</blockquote>
</div>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size: 12.0pt'><br> <br> <o:p></o:p></span></font></p>
</div>
</span>
<p class=MsoNormal style='margin-bottom:12.0pt'><font size=3 face="Times New Roman"><span style='font-size:12.0pt'>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 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 href="http://www.psoug.org/reference/merge.html" target="_blank">http://www .psoug.org/reference/merge.html</a> <o:p></o:p></span></font></p>
<table class=MsoNormalTable border=1 cellpadding=0 width="90%" bgcolor="#D8D8C4" style='width:90.0%;background:#D8D8C4'> <tr> <td width="25%" rowspan=2 style='width:25.0%;padding:.75pt .75pt .75pt .75pt'> <p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:12.0pt'><o:p> </o:p></span></font></p> </td> <td width="75%" style='width:75.0%;padding:.75pt .75pt .75pt .75pt'> <p class=MsoNormal><font size=3 face=Courier><span style='font-size:12.0pt; 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><o:p></o:p></p> </td> <td style='border:none' width=0><p class='MsoNormal'> </td> </tr> <tr height=19 style='height:14.25pt'> <td style='border:none;padding:0in 0in 0in 0in' width=386><p class='MsoNormal '> </td> <td style='height:14.25pt;border:none' width=0 height=19></td> </tr> </table>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size: 12.0pt'><o:p> </o:p></span></font></p>
</div>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size: 12.0pt'><o:p> </o:p></span></font></p>