Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.misc -> Re: SQL : problem with if statement
I'd use,
FOR rowData IN (SELECT * FROM someTable WHERE someCondition AND ROWNUM = 1) LOOP
Thomas Kyte wrote:
> 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
-- Thanks for your time Eric Kamradt hm: (801) 567-0912 mailto: kamradt_at_inconnect.com http://www.inconnect.com/~kamradt/resume.htmlReceived on Mon Aug 11 1997 - 00:00:00 CDT