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: Palmai Otto <otto.palmai_at_mail.online.hu>
Date: Mon, 13 Mar 2000 15:50:31 +0100
Message-ID: <8aiuvh$727$1@newsgate.elender.hu>


You can use COUNT(*) in your select statement, e.g.

SELECT COUNT(*) FROM mytab INTO myvar ... IF (myvar = 0) THEN
UPDATE ... Steve Ball <steve_at_REMOVEMEsdball.com> wrote in message news:38cce005$0$25792_at_lithium.news.uk.uu.net...
> 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.
>
> Any help appreciated,
>
> Thanks
>
> Steve
>
>
Received on Mon Mar 13 2000 - 08:50:31 CST

Original text of this message

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