Quick question: what if I need to update a record but the record doesn't exist? For this, I'll have to do INSERT first obviously. How can I tell if Insert is needed and not UPDATE (and vice versa)?
posted 10 years ago
If your database supports it, you can use a MERGE statement. MERGE is apparently a new feature in the ANSI SQL 2003 standard. So far, Oracle is the only database I know that supports it though (it's not in the docs for MySQl, Postgres, or HSQLDB, at least yet); I think it came in Oracle 9i, it's certainly present in 10g.