Re: Is this the sanctioned way to ascertain a table's existence?
Date: Sat, 17 Oct 2009 23:34:49 +1000
Ramon F Herrera wrote,on my timestamp of 17/10/2009 9:51 AM:
> I need to write code which creates a new record if it doesn't exist
> and modifies it otherwise. It seems that Oracle (actually, the SQL
> language) has two different statements for doing this, one being
> INSERT and the other UPDATE, right? (IOW, there is no single command
> like "create or replace" - I have to roll my own "create or replace").
> Therefore, my code should probably look like this:
> SELECT COUNT(1) INTO howMany FROM mytable WHERE <some constraint>
> if (howMany == 1)
> UPDATE mytable ();
> INSERT INTO mytable();
> I just want to make sure that that is the correct way.
Check MERGE statement: it was created precisely to cover this situation. Received on Sat Oct 17 2009 - 08:34:49 CDT