Re: Is this the sanctioned way to ascertain a table's existence?

From: Noons <>
Date: Sat, 17 Oct 2009 23:34:49 +1000
Message-ID: <hbcdkf$g1i$>

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 ();
> else
> INSERT INTO mytable();
> Right?
> 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

Original text of this message