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 Ranko Mosic

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

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>&nbsp;</div>
<div>Regards, Ranko.<br><br>&nbsp;</div>
<div><span class="gmail_quote">On 9/29/05, <b class="gmail_sendername"
>Mercadante, Thomas F (LABOR)</b> &lt;<a href="mailto:Thomas.Mercadante@(protected)
.state.ny.us">Thomas.Mercadante@(protected)</a>&gt; 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">&nbsp;</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">&nbsp;</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">&nbsp; Using</span></font></p><pre><font face="Arial
" color="navy" size="2"><span style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY:
Arial">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></font>select descr1 </pre><span class="q
"><pre><font face="Courier New" size="2"><span style="FONT-SIZE: 10pt">&nbsp;
&nbsp;&nbsp;&nbsp;from lkp_table1 where cd = p_cd1</span></font></pre></span>
<pre><font face="Courier New" size="2">
<span style="FONT-SIZE: 10pt">&nbsp;&nbsp; union</span></font></pre><pre><font
face="Courier New" size="2"><span style="FONT-SIZE: 10pt">&nbsp; &nbsp;select
descr2 </span></font></pre><span class="q"><pre><font face="Courier New" size=
"2"><span style="FONT-SIZE: 10pt">
&nbsp;&nbsp;&nbsp;&nbsp;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">&nbsp;</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">&nbsp;</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">&nbsp;</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">&nbsp;</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">&nbsp;<
/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>&nbsp;</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> &lt;<a
onclick="return top.js.OpenExtLink(window,event,this)" href="mailto:bdbafh
@(protected)" target="_blank">
bdbafh@(protected)</a>&gt; 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> &lt;<a
onclick="return top.js.OpenExtLink(window,event,this)" href="mailto:ranko.mosic
@(protected)" target="_blank">
ranko.mosic@(protected) </a>&gt; 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&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 ) ? </span></font></pre><pre><font
face="Courier New" size="2"><span style="FONT-SIZE: 10pt"><br>
<br>
Regards, Ranko.&nbsp; </span></font></pre>
<p><font face="Times New Roman" size="3"><span style="FONT-SIZE: 12pt">&nbsp;<
/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>&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 onclick="return top.js
.OpenExtLink(window,event,this)" 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 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">&nbsp;<
/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 &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></p></td>
<td style="BORDER-RIGHT: medium none; BORDER-TOP: medium none; BORDER-LEFT:
medium none; BORDER-BOTTOM: medium none" width="0">
<p>&nbsp;</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>&nbsp;</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">&nbsp;<
/span></font></p></div>
<p><font face="Times New Roman" size="3"><span style="FONT-SIZE: 12pt">&nbsp;<
/span></font></p></span></div></div></blockquote></div><br>