Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Mailing Lists -> Oracle-L -> Re: Pl/SQL-statement

Re: Pl/SQL-statement

From: Jonathan Gennick <jonathan_at_gennick.com>
Date: Mon, 10 Nov 2003 19:54:24 -0800
Message-ID: <F001.005D63E8.20031110195424@fatcity.com>


Hello Roland,

Do you even need PL/SQL for what you want to do?

rsis> I want to check whether field1 in table1 exists in
rsis> table3. If so then I want an insert statement to be
rsis> run...insert into table3

If the field *is* in table 3, you want to insert it into table 3 again? I find that an odd requirement. However, you might try something like:

INSERT INTO table3

   SELECT field1
   FROM table1
   WHERE field1 IN (SELECT DISTINCT field1 FROM table3);

EXISTS might work better than IN. You might need to adjust your SELECT column list to match your target table. I don't know what other columns are in table3. If table3 is really large, I'd consider using EXISTS and getting rid of DISTINCT. Well, you might need to try a few variations to figure out which performs the best.

Best regards,

Jonathan Gennick --- Brighten the corner where you are http://Gennick.com * 906.387.1698 * mailto:jonathan@gennick.com

Join the Oracle-article list and receive one article on Oracle technologies per month by email. To join, visit http://four.pairlist.net/mailman/listinfo/oracle-article, or send email to Oracle-article-request_at_gennick.com and include the word "subscribe" in either the subject or body.

Monday, November 10, 2003, 9:54:25 AM, roland.skoldblom_at_ica.se (roland.skoldblom_at_ica.se) wrote: rsis> Hallo,

rsis> I would like to do the following with an sql( pl/sql) statement.

rsis> I have table1 and table2 andtable3.

rsis> I want to check whether field1 in table1 exists in table3. If so then I want an insert statement to be run...insert into table3..... rsis> If it doesnt find that value then th escript will go to table2 and check if the vaules exists in that table, if it finds it then I want another insert statement to be run.

rsis> Please help me with an easy example, i dont know if this is so simply but I cantget it right though.

rsis> Thanks

rsis> Roland

rsis> --
rsis> Please see the official ORACLE-L FAQ: http://www.orafaq.net

--

Please see the official ORACLE-L FAQ: http://www.orafaq.net
--

Author: Jonathan Gennick
  INET: jonathan_at_gennick.com

Fat City Network Services    -- 858-538-5051 http://www.fatcity.com
San Diego, California        -- Mailing list and web hosting services
---------------------------------------------------------------------
To REMOVE yourself from this mailing list, send an E-Mail message to: ListGuru_at_fatcity.com (note EXACT spelling of 'ListGuru') and in the message BODY, include a line containing: UNSUB ORACLE-L (or the name of mailing list you want to be removed from). You may also send the HELP command for other information (like subscribing). Received on Mon Nov 10 2003 - 21:54:24 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US