Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Data Bases > Oracle Miscellaneous > Re: conditional...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 3 of 3 Topic 6866 of 7201
Post > Topic >>

Re: conditional insert with values; insert into .. values(...) where

by Ed Prochak <edprochak@[EMAIL PROTECTED] > Apr 30, 2008 at 10:01 AM

On Apr 29, 11:08 am, md <mardahl2...@[EMAIL PROTECTED]
> wrote:
> This is what I wish I could to do.
>
> insert into table_x (a, b, c)
>   values(1, 2, 3)
>     where not exist (select * from table_x where a = 2);

(BTW it helps to spell EXISTS correctly. Best is to copy and paste the
query you tried instead of retyping it because something always goes
wrong when manually retyping.)
>
> Thank you.
>
you are just so close to seeing the answer, try this:
drop table ejp;

create table ejp as
 select 3 a,2 b,1 c from dual ;

select * from ejp ;

 insert into ejp (a, b, c)
           select 2, 2, 3   from dual
               where not exists
                (select * from ejp where a = 2);

select * from ejp ;


 insert into ejp (a, b, c)
           select 1, 2, 3   from dual
               where not exists
                (select * from ejp where a = 2);

select * from ejp ;

And the results:
Table dropped.
Table created.

         A          B          C
---------- ---------- ----------
         3          2          1


1 row selected.
1 row created.

         A          B          C
---------- ---------- ----------
         3          2          1
         2          2          3


2 rows selected.
created.

         A          B          C
---------- ---------- ----------
         3          2          1
         2          2          3


2 rows selected.

(sorry for the separate script/output. I ran this from Toad.

HTH,
  Ed
 




 3 Posts in Topic:
conditional insert with values; insert into .. values(...) where
md <mardahl2000@[EMAIL  2008-04-29 08:08:52 
Re: conditional insert with values; insert into .. values(...) w
Peter Nilsson <airia@[  2008-04-29 20:27:31 
Re: conditional insert with values; insert into .. values(...) w
Ed Prochak <edprochak@  2008-04-30 10:01:48 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Wed Oct 15 13:51:17 CDT 2008.