From oracle-l-bounce@freelists.org Thu Sep 29 08:03:09 2005 Return-Path: Received: from air891.startdedicated.com (root@localhost) by orafaq.com (8.12.10/8.12.10) with ESMTP id j8TD36tb000539 for ; Thu, 29 Sep 2005 08:03:06 -0500 X-ClientAddr: 206.53.239.180 Received: from turing.freelists.org (freelists-180.iquest.net [206.53.239.180]) by air891.startdedicated.com (8.12.10/8.12.10) with ESMTP id j8TD2l6H000460 for ; Thu, 29 Sep 2005 08:02:48 -0500 Received: from localhost (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id D106C1EFFDC; Thu, 29 Sep 2005 08:02:39 -0500 (EST) Received: from turing.freelists.org ([127.0.0.1]) by localhost (turing [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 32439-07; Thu, 29 Sep 2005 08:02:39 -0500 (EST) Received: from turing (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id 4ED611EFFD5; Thu, 29 Sep 2005 08:02:39 -0500 (EST) X-MimeOLE: Produced By Microsoft Exchange V6.5.7226.0 Content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----_=_NextPart_001_01C5C4F5.C7270692" Subject: RE: Dimension table load - PLSQL question Date: Thu, 29 Sep 2005 09:00:33 -0400 Message-ID: X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: Dimension table load - PLSQL question thread-index: AcXE8/XXc4RPHLmhTbqnGsF7M20sCAAAW67A From: "Mercadante, Thomas F (LABOR)" To: Cc: "ORACLE-L" X-OriginalArrivalTime: 29 Sep 2005 13:00:34.0249 (UTC) FILETIME=[C7780390:01C5C4F5] X-archive-position: 26086 X-ecartis-version: Ecartis v1.0.0 Sender: oracle-l-bounce@freelists.org Errors-To: oracle-l-bounce@freelists.org X-original-sender: Thomas.Mercadante@labor.state.ny.us Precedence: normal Reply-To: Thomas.Mercadante@labor.state.ny.us X-list: oracle-l X-Virus-Scanned: by amavisd-new-20030616-p9 (Debian) at avenirtech.net X-mailscan-MailScanner-Information: Please contact the ISP for more information X-mailscan-MailScanner: Found to be clean X-MailScanner-From: oracle-l-bounce@freelists.org X-Spam-Level: X-Spam-Checker-Version: SpamAssassin 2.63 (2004-01-11) on air891.startdedicated.com X-Spam-Status: No, hits=-3.3 required=5.0 tests=AWL,BAYES_00,HTML_60_70, HTML_FONTCOLOR_UNKNOWN,HTML_MESSAGE autolearn=no version=2.63 ------_=_NextPart_001_01C5C4F5.C7270692 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Ronko, =20 Could you union all of the selects into one query and then use merge? =20 Merge (table) Using select descr1=20 from lkp_table1 where cd =3D p_cd1 union select descr2=20 from lkp_table2 where cd =3D p_cd2 etc=20 =20 etc......... =20 Would this work? =20 Tom =20 ________________________________ From: oracle-l-bounce@freelists.org [mailto:oracle-l-bounce@freelists.org] 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 =20 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.=20 I have one table being inserted from 6 tables.=20 Thanks genius. =20 On 9/28/05, Paul Drake wrote:=20 On 9/28/05, Ranko Mosic wrote:=20 Hi,=20 =09 requirement:=20 =09 - input parameters are codes p_cd1, p_cd2, ... =09 - for these codes I get descriptions ( select descr1 into v_descr1 from=20 =09 =09 lkp_table1 where cd =3D p_cd1; select descr2 into v_descr2 from lkp_table2 where=20 =09 =09 cd =3D p_cd2 etc ) =09 - check if table t has records where t.descr1 =3D v_descr1 =09 and t.descr2 =3D v_descr2 and on and on ....;=20 =09 - if row exists return primary key;=20 =09 - if not then insert.=20 =09 =09 =09 What is the best way of doing it ( simplest ) ?=20 =09 =09 =09 =09 Regards, Ranko. =20 =20 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.=20 A search of "oracle 10.1 upsert" in google.com + "I'm feeling lucky" produced this for me.=20 Perhaps you might get lucky too. Paul http://www.psoug.org/reference/merge.html=20 =20 MERGE INTO USING ON () WHEN MATCHED THEN WHEN NOT MATCHED THEN ;=20 =20 =09 =20 =20 ------_=_NextPart_001_01C5C4F5.C7270692 Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: quoted-printable

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 =3D p_cd1
   =
union
  =
 select descr2 
    from lkp_table2 where =
cd =3D p_cd2 etc 

 
etc………
 
Would =
this work?

 

Tom

 


From: oracle-l-bounce@freelists.org [mailto:oracle-l-bounce@freelists.org] = 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@gmail.com> wrote:

On 9/28/05, Ranko Mosic <ranko.mosic@gmail.com > 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 =3D p_cd1; select descr2 into v_descr2 from = lkp_table2 where

cd =3D p_cd2 etc )
- check if table t has records  where t.descr1 =3D v_descr1
   and t.descr2 =3D 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 + "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>; =

 

 

 

 

------_=_NextPart_001_01C5C4F5.C7270692-- -- http://www.freelists.org/webpage/oracle-l