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 Igor Neyman

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

"when matched" clause is optional, so you should be fine without
updates.
As for returning PK, regular "INSERT" has "RETURNING" clause, but I
don't see one for "insert" used withing "MERGE".  File "enhancement
request" with Oracle :)

__ ____ ____ ____ ____ ____ ____

From: oracle-l-bounce@(protected)
[mailto:oracle-l-bounce@(protected)] On Behalf Of Ranko Mosic
Sent: Thursday, September 29, 2005 9:34 AM
To: Igor Neyman
Cc: Paul Drake; ORACLE-L
Subject: Re: Dimension table load - PLSQL question


What about returning key if record exists ? There is no update
happening.

Thanks, rm.


On 9/29/05, Igor Neyman <ineyman@(protected)> wrote:

  Does it make a difference: 1 table or 6?
 
  MERGE INTO t
     USING (SELECT(select descr1 from lkp_table1 where cd =
p_cd1) AS v_descr1,
                                 select descr2 from lkp_table2
where cd = p_cd2) AS v_descr2 ,
                                 .... etc. )from dual) c
     ON (t.descr1 = c.v_descr1 and t.descr2 = c.v_descr2 and ...
etc)
     WHEN NOT MATCHED INSERT (t.descr1, t.descr2, ...)
         VALUES (c.v_descr1, c.v_descr2, ...)
 
  Really, no need to react the way, you did...
 
 
  Igor Neyman
 

 
__ ____ ____ ____ ____ ____ ____

  From: oracle-l-bounce@(protected) [mailto:
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>;  





<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=us-ascii">
<META content="MSHTML 6.00.2900.2722" name=GENERATOR></HEAD>
<BODY>
<DIV dir=ltr align=left><SPAN class=302513813-29092005><FONT face=Arial
color=#0000ff size=2>"when matched" clause is optional, so you should be fine
without updates.</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=302513813-29092005><FONT face=Arial
color=#0000ff size=2>As for returning PK, regular "INSERT" has "RETURNING"
clause, but I don't see one for "insert" used withing "MERGE".&nbsp; File
"enhancement request" with Oracle :)</FONT></SPAN></DIV><BR>
<DIV class=OutlookMessageHeader lang=en-us dir=ltr align=left>
<HR tabIndex=-1>
<FONT face=Tahoma size=2><B>From:</B> oracle-l-bounce@(protected)
[mailto:oracle-l-bounce@(protected)] <B>On Behalf Of </B>Ranko
Mosic<BR><B>Sent:</B> Thursday, September 29, 2005 9:34 AM<BR><B>To:</B> Igor
Neyman<BR><B>Cc:</B> Paul Drake; ORACLE-L<BR><B>Subject:</B> Re: Dimension
table
load - PLSQL question<BR></FONT><BR></DIV>
<DIV></DIV>
<DIV>What about returning key if record exists ? There is no update happening.
</DIV>
<DIV>&nbsp;</DIV>
<DIV>Thanks, rm.<BR><BR>&nbsp;</DIV>
<DIV><SPAN class=gmail_quote>On 9/29/05, <B class=gmail_sendername>Igor
Neyman</B> &lt;<A
href="mailto:ineyman@(protected)">ineyman@(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 dir=ltr align=left><SPAN><FONT face=Arial color=#0000ff size=2>Does it
 make a difference: 1 table or 6?</FONT></SPAN></DIV>
 <DIV dir=ltr align=left><SPAN><FONT face=Arial color=#0000ff
 size=2></FONT></SPAN>&nbsp;</DIV>
 <DIV dir=ltr align=left><SPAN><FONT face=Arial color=#0000ff size=2>MERGE
INTO
 t</FONT></SPAN></DIV>
 <DIV dir=ltr align=left><SPAN>&nbsp;&nbsp;&nbsp; <FONT face=Arial
 color=#0000ff size=2>USING (SELECT(<FONT color=#000000 size=3>select descr1
 from&nbsp;lkp_table1 where cd = p_cd1) AS
 v_descr1,&nbsp;</FONT></FONT></SPAN></DIV>
 <DIV dir=ltr align=left><SPAN><FONT face=Arial color=#0000ff size=2><FONT
 color=#000000
 size=3>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 select descr2&nbsp;from lkp_table2 where&nbsp;cd = p_cd2) AS
 v_descr2&nbsp;,</FONT></FONT></SPAN> </DIV>
 <DIV dir=ltr
 align=left><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<FONT
 face=Arial>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;
 .... etc. )from dual) c</FONT></SPAN></DIV>
 <DIV dir=ltr align=left><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;<FONT face=Arial>ON
 (t.descr1 = c.v_descr1</FONT>&nbsp;<FONT face=Arial>and t.descr2 = c.v_descr2
 and ... etc)</FONT></SPAN></DIV>
 <DIV dir=ltr align=left><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;WHEN NOT MATCHED INSERT
 (t.<FONT face=Arial>descr1</FONT>, t.<FONT face=Arial>descr2</FONT>,
 ...)&nbsp;</SPAN></DIV>
 <DIV dir=ltr align=left><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 VALUES (<FONT face=Arial>c.v_descr1, c.v_descr2, ...)</FONT></SPAN></DIV>
 <DIV><FONT face=Arial color=#0000ff size=2></FONT>&nbsp;</DIV>
 <DIV><SPAN><FONT face=Arial color=#0000ff size=2>Really, no need to
 react&nbsp;the way, you did...</FONT></SPAN></DIV><SPAN class=sg>
 <DIV><SPAN><FONT face=Arial color=#0000ff size=2></FONT></SPAN>&nbsp;</DIV>
 <DIV><SPAN><FONT face=Arial color=#0000ff size=2>Igor
 Neyman</FONT></SPAN></DIV></SPAN>
 <DIV><SPAN class=e id=q_106a20a7e3aa3092_2>
 <DIV dir=ltr align=left><BR>&nbsp;</DIV>
 <DIV lang=en-us dir=ltr align=left>
 <HR>
 <FONT face=Tahoma size=2><B>From:</B> <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>On Behalf Of </B>Ranko
 Mosic<BR><B>Sent:</B> Thursday, September 29, 2005 8:45 AM<BR><B>To:</B> Paul
 Drake<BR><B>Cc:</B> ORACLE-L<BR><B>Subject:</B> Re: Dimension table load -
 PLSQL question <BR></FONT><BR>&nbsp;</DIV>
 <DIV></DIV>
 <DIV>Thanks for very helpful, no patronizing answer. If you've read more
 carefully what the problem is</DIV>
 <DIV>you'd see that MERGE can't work because it works on one table upserting
 another. </DIV>
 <DIV>I have one table being inserted from 6 tables. </DIV>
 <DIV>Thanks genius.<BR><BR>&nbsp;</DIV>
 <DIV><SPAN class=gmail_quote>On 9/28/05, <B class=gmail_sendername>Paul
 Drake</B> &lt;<A onclick="return top.js.OpenExtLink(window,event,this)"
 href="mailto:bdbafh@(protected)" target=_blank>bdbafh@(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><SPAN>On 9/28/05, <B class=gmail_sendername>Ranko Mosic</B> &lt;<A
   onclick="return top.js.OpenExtLink(window,event,this)"
   href="mailto:ranko.mosic@(protected)" target=_blank>ranko.mosic@(protected)
   </A>&gt; wrote:
   <DIV><SPAN class=gmail_quote></SPAN>
   <BLOCKQUOTE class=gmail_quote
   style="PADDING-LEFT: 1ex; MARGIN: 0pt 0pt 0pt 0.8ex; BORDER-LEFT: rgb(204
,204,204) 1px solid"><PRE>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
<BR>lkp_table1 where cd = p_cd1; select descr2 into v_descr2 from lkp_table2
where
<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 ) ?
<BR><BR>Regards, Ranko.  <BR></PRE><BR></BLOCKQUOTE></DIV><BR></SPAN></DIV
>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> <BR><BR>
   <TABLE width="90%" bgColor=#d8d8c4 border=1>
     <TBODY>
     <TR>
       <TD width="25%" rowSpan=2><BR></TD>
       <TD width="75%"><FONT face=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;;
 </FONT></TD></TR></TBODY></TABLE><BR></BLOCKQUOTE></DIV><BR></SPAN></DIV><
/BLOCKQUOTE></DIV><BR></BODY></HTML>