Insert and Where clause [message #19375] |
Wed, 13 March 2002 10:47 |
Rob
Messages: 70 Registered: January 2000
|
Member |
|
|
Can you have an Insert statement with a where clause? I'd like to only perform an insert if a record doesn't exist (in 1 SQL statement--no cursors)...but I can't seem to get the correct syntax (logic?)
Thanks, Rob
|
|
|
Re: Insert and Where clause [message #19377 is a reply to message #19375] |
Wed, 13 March 2002 11:16 |
Jon
Messages: 483 Registered: May 2001
|
Senior Member |
|
|
Not directly but as usual, there is a work around:
1 insert into table1
2* (select 'Jon' from dual where not exists (select 1 from table1 where col1 = 'Jon'))
16:13:46 ==> /
1 row created.
16:13:49 ==> /
0 rows created.
The first time it inserted 'Jon' because there was no 'Jon' in col1; the second time it didn't create a row because there was.
|
|
|