Home » SQL & PL/SQL » SQL & PL/SQL » Insert and Where clause
Insert and Where clause [message #19375] Wed, 13 March 2002 10:47 Go to next message
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 Go to previous message
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.
Previous Topic: Replacing values in CLOB column
Next Topic: Temporary Table Problem
Goto Forum:
  


Current Time: Fri Apr 26 23:06:23 CDT 2024