Links
Home
Oracle DBA Forum
Frequent Oracle Errors
TNS:could not resolve the connect identifier specified
Backtrace message unwound by exceptions
invalid identifier
PL/SQL compilation error
internal error
missing expression
table or view does not exist
end-of-file on communication channel
TNS:listener unknown in connect descriptor
insufficient privileges
PL/SQL: numeric or value error string
TNS:protocol adapter error
ORACLE not available
target host or object does not exist
invalid number
unable to allocate string bytes of shared memory
resource busy and acquire with NOWAIT specified
error occurred at recursive SQL level string
ORACLE initialization or shutdown in progress
archiver error. Connect internal only, until freed
snapshot too old
unable to extend temp segment by string in tablespace
Credential retrieval failed
missing or invalid option
invalid username/password; logon denied
unable to create INITIAL extent for segment
out of process memory when trying to allocate string bytes
shared memory realm does not exist
cannot insert NULL
TNS:unable to connect to destination
remote database not found'>ora-02019
exception encountered: core dump
inconsistent datatypes
no data found
TNS:operation timed out
PL/SQL: could not find program
existing state of packages has been discarded
maximum number of processes exceeded
error signaled in parallel query server
ORACLE instance terminated. Disconnection forced
TNS:packet writer failure
see ORA-12699
missing right parenthesis
name is already used by an existing object
cannot identify/lock data file
invalid file operation
quoted string not properly terminated
Dimension table load - PLSQL question

Dimension table load - PLSQL question

2005-09-29       - By Mercadante, Thomas F (LABOR)

Reply:     1     2     3     4     5     6     7     8     9     10     >>  

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>;

 
   






<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft
-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns="http:
//www.w3.org/TR/REC-html40">

<head>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii">
<meta name=Generator content="Microsoft Word 11 (filtered medium)">
<!--[if !mso]>
<style>
v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style>
<![endif]-->
<style>
<!--
/* Font Definitions */
@(protected)
  {font-family:Courier;
  panose-1:2 7 4 9 2 2 5 2 4 4;}
@(protected)
  {font-family:Tahoma;
  panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
  {margin:0in;
  margin-bottom:.0001pt;
  font-size:12.0pt;
  font-family:"Times New Roman";}
a:link, span.MsoHyperlink
  {color:blue;
  text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
  {color:blue;
  text-decoration:underline;}
pre
  {margin:0in;
  margin-bottom:.0001pt;
  font-size:10.0pt;
  font-family:"Courier New";}
span.EmailStyle20
  {mso-style-type:personal-reply;
  font-family:Arial;
  color:navy;}
@(protected) Section1
  {size:8.5in 11.0in;
  margin:1.0in 1.25in 1.0in 1.25in;}
div.Section1
  {page:Section1;}
-->
</style>

</head>

<body lang=EN-US link=blue vlink=blue>

<div class=Section1>

<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>Ronko,<o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'><o:p>&nbsp;</o:p></span></font></p>

<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=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'><o:p>&nbsp;</o:p></span></font></p>

<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>Merge (table)<o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>&nbsp; Using<o:p></o:p></span></font></p>

<pre><font size=2 color=navy face=Arial><span style='font-size:10.0pt;
font-family:Arial;color:navy'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></font
>select descr1 <o:p></o:p></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'>&nbsp;&nbsp;&nbsp;
&nbsp;from lkp_table1 where cd = p_cd1<o:p></o:p></span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'>&nbsp;&nbsp; union<o:p
></o:p></span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'>&nbsp; &nbsp;select
descr2 <o:p></o:p></span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'>&nbsp;&nbsp;&nbsp;
&nbsp;from lkp_table2 where cd = p_cd2 etc <br>
<br>
<o:p></o:p></span></font></pre><pre><font size=2 face="Courier New"><span
style='font-size:10.0pt'><o:p>&nbsp;</o:p></span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'>etc&#8230;&#8230;&
#8230;<o:p></o:p></span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'><o:p>&nbsp;</o:p><
/span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'>Would this work?</span
></font><font
color=navy face=Arial><span style='font-family:Arial;color:navy'><o:p></o:p><
/span></font></pre>

<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'><o:p>&nbsp;</o:p></span></font></p>

<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>Tom<o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'><o:p>&nbsp;</o:p></span></font></p>

<div>

<div class=MsoNormal align=center style='text-align:center'><font size=3
face="Times New Roman"><span style='font-size:12.0pt'>

<hr size=2 width="100%" align=center tabindex=-1>

</span></font></div>

<p class=MsoNormal><b><font size=2 face=Tahoma><span style='font-size:10.0pt;
font-family:Tahoma;font-weight:bold'>From:</span></font></b><font size=2
face=Tahoma><span style='font-size:10.0pt;font-family:Tahoma'>
oracle-l-bounce@(protected) [mailto:oracle-l-bounce@(protected)] <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><o:p></o:p></p>

</div>

<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'><o:p>&nbsp;</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>

</div>

<div>

<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'>Thanks genius.<br>
<br>
&nbsp;<o:p></o:p></span></font></p>

</div>

<div>

<p class=MsoNormal><span class=gmailquote><font size=3 face="Times New Roman">
<span
style='font-size:12.0pt'>On 9/28/05, <b><span style='font-weight:bold'>Paul
Drake</span></b> &lt;<a href="mailto:bdbafh@(protected)">bdbafh@(protected)</a>&gt;
wrote:</span></font></span> <o:p></o:p></p>

<div><span id="q_1069edab88b6ca8a_0">

<p class=MsoNormal><span class=e><font size=3 face="Times New Roman"><span
style='font-size:12.0pt'>On 9/28/05, <b><span style='font-weight:bold'>Ranko
Mosic</span></b> &lt;<a href="mailto:ranko.mosic@(protected)" target="_blank"
>ranko.mosic@(protected)
</a>&gt; wrote: <o:p></o:p></span></font></span></p>

<div>

<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&nbsp; where t.descr1 = v_descr1<br>
&nbsp;&nbsp; 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.&nbsp; <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>&nbsp;</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>
&quot;Simplest way&quot; is to solicit opinions without using a search engine
or checking the documentation.<br>
Its also usually &quot;simplest&quot; to leverage the existing provided
functionality, rather than writing your own routines, error handling, etc. <br>
<br>
A search of &quot;oracle 10.1 upsert&quot; in <a href="http://google.com/"
target="_blank">google.com</a> + &quot;I'm feeling lucky&quot; 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>&nbsp;</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 &lt;hint&gt; INTO &lt;table_name&gt;<br>
 USING &lt;table_view_or_query&gt;<br>
 ON (&lt;condition&gt;)<br>
 WHEN MATCHED THEN &lt;update_clause&gt;<br>
 WHEN NOT MATCHED THEN &lt;insert_clause&gt;; </span></font><o:p></o:p></p>
 </td>
 <td style='border:none' width=0><p class='MsoNormal'>&nbsp;</td>
</tr>
<tr height=19 style='height:14.25pt'>
 <td style='border:none;padding:0in 0in 0in 0in' width=386><p class='MsoNormal
'>&nbsp;</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>&nbsp;</o:p></span></font></p>

</div>

<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'><o:p>&nbsp;</o:p></span></font></p>

</div>

</body>

</html>