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

From: Dan Blum <tool_at_panix.com>
Date: Fri, 16 Oct 2009 23:59:33 +0000 (UTC)
Message-ID: <hbb1d5$qsg$1_at_reader1.panix.com>



In comp.databases.oracle.misc Ramon F Herrera <ramon_at_conexus.net> wrote:
> Since the following question is conceptually similar to the previous,
> I will tag it along this thread.

> 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.

Take a look at the MERGE statement.

-- 
_______________________________________________________________________
Dan Blum					         tool_at_panix.com	
"I wouldn't have believed it myself if I hadn't just made it up."
Received on Fri Oct 16 2009 - 18:59:33 CDT

Original text of this message