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: Simple IF statement

Re: Simple IF statement

From: Michel Cadot <micadot_at_netcourrier.com>
Date: Mon, 23 Aug 1999 18:31:03 +0200
Message-ID: <7prt1d$15a$1@oceanite.cybercable.fr>


For the first point (IF SELECT..), a slight modification of your PL/SQL and you can do what you want :

DECLARE
 CNT NUMBER;
BEGIN
 SELECT COUNT(*) INTO CNT FROM daily_sales;  IF CNT < 1 THEN
  <do something>
 ELSE
  <do other thing>
 END IF;
END; For the second point (do the select), you have to get the result of the query in a variable, for instance:

DECLARE
 CNT NUMBER;
 type cursType is ref cursor;
 curs cursType;
BEGIN
 SELECT COUNT(*) INTO CNT FROM daily_sales;  IF CNT < 1 THEN
  open curs for select * from author;
  while curs%found loop
   <do something>
  end loop;
 ELSE
  open curs for select * from other;
  while curs%found loop
   <do other thing>
  end loop;
 END IF;
 close curs;
END; Dan Fluet a écrit dans le message <37C160B8.FCF11D5C_at_bdsinc.com>...
>I know this should be easy but it is Monday.
>
>In SQL Server there is an IF EXISTS function. Is there anything
>similiar to that in Oracle? Here is a simplified query of what I am
>trying to do.
>
>If there is something in the daily_sales do the first select if not do
>the second.
>
>BEGIN
> IF (SELECT COUNT(*) FROM daily_sales) < 1 THEN
> SELECT * FROM author;
> ELSE
> SELECT * FROM other;
> END IF;
>END;
>
Received on Mon Aug 23 1999 - 11:31:03 CDT

Original text of this message

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