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: Exist clause in PL/SQL

Re: Exist clause in PL/SQL

From: Thomas Kyte <tkyte_at_us.oracle.com>
Date: 12 Nov 2001 12:04:31 -0800
Message-ID: <9spa0f01ljv@drn.newsguy.com>


In article <1b00d968.0111120741.6e92e5fb_at_posting.google.com>, yavior_at_mercury.co.il says...
>
>Hi,
>Is there in PL/SQL any replacement for SQL-Server's "If exist/If not
>exist" clause?
>I need to do something like : if not exists (select * from Table1
>where Field1=...) Insert into Table1 (Field1, Field2,...) values (...,
>...,...)
>
>thanks

  if not exists ( select .... )
  then

         insert ...
  end

would be the same as:

  for x in ( select * from dual where NOT EXISTS ( select .... ) )   loop

      insert ...
  end loop;            

and   

  for x in ( select * from dual where EXISTS ( select .... ) )   loop

     ....
  end loop

would be the same as

  if exists ( select .... )

--
Thomas Kyte (tkyte@us.oracle.com)             http://asktom.oracle.com/ 
Expert one on one Oracle, programming techniques and solutions for Oracle.
http://www.amazon.com/exec/obidos/ASIN/1861004826/  
Opinions are mine and do not necessarily reflect those of Oracle Corp 
Received on Mon Nov 12 2001 - 14:04:31 CST

Original text of this message

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