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: SQL : problem with if statement

Re: SQL : problem with if statement

From: Thomas Kyte <tkyte_at_us.oracle.com>
Date: 1997/08/11
Message-ID: <33f02ddd.6524071@newshost>#1/1

In pl/sql it will look like:

....

   select count(*) into local_variable from dual     where exists ( select k_num from kunde )

   if ( local_variable = 1 ) then

       ....
   end if;

....

OR

   for x in (select * from DUAL where exists ( select k_num from kunde )) loop

      ....
   end loop;

It looks a little funny to use a loop instead of an IF/END-IF statement but it would (in this case) have the same effect. DUAL is a row row, one column table. If the row exists in kunde, the loop will go once. If it does not exist in kunde, the loop will not execute at all.

On Mon, 11 Aug 1997 13:51:26 GMT, ritscher_at_isl.uni-bremen.de (Astrid Ritscher) wrote:

>Hi,
>I would like to know if there is any possibility to code in PSQL
>something like this (from Sybase Transact SQL):
>
>IF EXISTS (SELECT k_num FROM kunde)
>BEGIN
>...
>END
>
>which tests for the existece of a certain row. This is faster than
>counting the number of rows because EXISTS stops the select after
>having found the first row.
>
>Thank you for any hints,
>Astrid.

Thomas Kyte
tkyte_at_us.oracle.com
Oracle Government
Bethesda MD

http://govt.us.oracle.com/ -- downloadable utilities



Opinions are mine and do not necessarily reflect those of Oracle Corporation Received on Mon Aug 11 1997 - 00:00:00 CDT

Original text of this message

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