Conditional Insert??? [message #28821] |
Fri, 23 January 2004 11:19  |
rdx
Messages: 2 Registered: June 2003
|
Junior Member |
|
|
Is there a way to have an INSERT statement with a where clause? I need to insert to a table based only when a certain condition is satisfied on another table and I don't have the luxury of using multiple statement (otherwise would have been a piece of cake using PLSQL ) .. Need to do it in a single statement .. so what are my choices ??
Thanks in advance
rdx
|
|
|
|
Re: Conditional Insert??? [message #28827 is a reply to message #28821] |
Sat, 24 January 2004 07:38  |
William Robertson
Messages: 1643 Registered: August 2003 Location: London, UK
|
Senior Member |
|
|
You could try something like:
INSERT INTO sometable
( col1, col2, col3 )
SELECT a, b, c
FROM dual
WHERE EXISTS
( SELECT 1
FROM othertable
WHERE somecondition ); or
INSERT INTO sometable
( col1, col2, col3 )
SELECT a, b, c
FROM othertable
WHERE somecondition
AND rownum = 1;
In 9i you also have a CASE-like syntax available with INSERT ALL/FIRST, though that doesn't sound like quite what you want here.
|
|
|