Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Re: 'IF EXISTS' functionality in Oracle SQL

Re: 'IF EXISTS' functionality in Oracle SQL

From: Chris Mac <chris_mac_at_my-deja.com>
Date: Mon, 13 Mar 2000 13:45:07 +0000
Message-ID: <38CCF0E3.B7B9B65D@my-deja.com>

Steve Ball wrote:

> All,
>
> I have some SQL written that worked on a Sybase or MS SQL Server db, but not
> Oracle:
>
> if exists (select ...)
> update my_table
> set my_table.status = "65"
> where
> my_table.id = ...
>
> Basically, I'd like to find out if something exists, and if it does (or
> doesn't!) contain the data, I'd like to update the table.
>
> I don't think (I've looked) that there is the equivalent 'if exists' in
> Oracle, and I've looked at the decode statement, but I could not see that it
> would work for what I wanted.
>
> What I'm looking to do is add a row to a table ONLY if some other select
> returns 0 rows.

STORED procedure



begin

    select * from a,b,c
    update blah_blah_blah
end
exception

    when no_data_found

        insert into blah_blah_blah
[...]

HTH Received on Mon Mar 13 2000 - 07:45:07 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US