dbTalk Databases Forums  

conditional insert with values; insert into .. values(...) where notexist (....);

comp.databases.oracle.misc comp.databases.oracle.misc


Discuss conditional insert with values; insert into .. values(...) where notexist (....); in the comp.databases.oracle.misc forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
md
 
Posts: n/a

Default conditional insert with values; insert into .. values(...) where notexist (....); - 04-29-2008 , 10:08 AM






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);

Thank you.




additional info:
I've seen conditional inserts without values(....), as in

INSERT INTO clients
(client_id, client_name, client_type)
SELECT supplier_id, supplier_name, 'advertising'
FROM suppliers
WHERE NOT EXISTS (SELECT *
FROM clients
WHERE clients.client_id =
suppliers.supplier_id);


Reply With Quote
  #2  
Old   
Peter Nilsson
 
Posts: n/a

Default Re: conditional insert with values; insert into .. values(...) wherenot exist (....); - 04-29-2008 , 10:27 PM






md wrote:
Quote:
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);

Thank you.
Look up 'insert when'.

--
Peter


Reply With Quote
  #3  
Old   
Peter Nilsson
 
Posts: n/a

Default Re: conditional insert with values; insert into .. values(...) wherenot exist (....); - 04-29-2008 , 10:27 PM



md wrote:
Quote:
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);

Thank you.
Look up 'insert when'.

--
Peter


Reply With Quote
  #4  
Old   
Peter Nilsson
 
Posts: n/a

Default Re: conditional insert with values; insert into .. values(...) wherenot exist (....); - 04-29-2008 , 10:27 PM



md wrote:
Quote:
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);

Thank you.
Look up 'insert when'.

--
Peter


Reply With Quote
  #5  
Old   
Peter Nilsson
 
Posts: n/a

Default Re: conditional insert with values; insert into .. values(...) wherenot exist (....); - 04-29-2008 , 10:27 PM



md wrote:
Quote:
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);

Thank you.
Look up 'insert when'.

--
Peter


Reply With Quote
  #6  
Old   
Ed Prochak
 
Posts: n/a

Default Re: conditional insert with values; insert into .. values(...) wherenot exist (....); - 04-30-2008 , 12:01 PM



On Apr 29, 11:08 am, md <mardahl2... (AT) yahoo (DOT) com> wrote:
Quote:
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.)
Quote:
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


Reply With Quote
  #7  
Old   
Ed Prochak
 
Posts: n/a

Default Re: conditional insert with values; insert into .. values(...) wherenot exist (....); - 04-30-2008 , 12:01 PM



On Apr 29, 11:08 am, md <mardahl2... (AT) yahoo (DOT) com> wrote:
Quote:
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.)
Quote:
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


Reply With Quote
  #8  
Old   
Ed Prochak
 
Posts: n/a

Default Re: conditional insert with values; insert into .. values(...) wherenot exist (....); - 04-30-2008 , 12:01 PM



On Apr 29, 11:08 am, md <mardahl2... (AT) yahoo (DOT) com> wrote:
Quote:
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.)
Quote:
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


Reply With Quote
  #9  
Old   
Ed Prochak
 
Posts: n/a

Default Re: conditional insert with values; insert into .. values(...) wherenot exist (....); - 04-30-2008 , 12:01 PM



On Apr 29, 11:08 am, md <mardahl2... (AT) yahoo (DOT) com> wrote:
Quote:
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.)
Quote:
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


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.