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

From: joel garry <joel-garry_at_home.com>
Date: Fri, 16 Oct 2009 16:59:34 -0700 (PDT)
Message-ID: <1168eb2a-3465-490c-9197-642f709c700f_at_w37g2000prg.googlegroups.com>



On Oct 16, 4:51 pm, Ramon F Herrera <ra..._at_conexus.net> wrote:

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

http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:61865893444475

jg

--
_at_home.com is bogus.
http://www.theregister.co.uk/2009/10/16/ibm_intel_insider_trading/
Received on Fri Oct 16 2009 - 18:59:34 CDT

Original text of this message