Re: Using SubQueries

From: Will <wkooiman_at_earthlink.net>
Date: 5 Jun 2002 20:39:16 -0700
Message-ID: <7256fcf8.0206051939.5164c704_at_posting.google.com>


marksmithy69_at_yahoo.com (Mark) wrote in message news:<13e212f9.0206051219.67880b5e_at_posting.google.com>...
> I am a beginner, so forgive me for the easy questions. How do I use a
> subquery in an if statement? For example, I want to write something
> like this...
>
> If last_name NOT IN (Select last_name from People) then
> ...
>
> Basically, I have a table which contains last names, and I want to
> compare it to the last name field in the People table. Whenever I try
> it, I get an error telling me that a subquery cannot be used in this
> context. Is there another way that I can do this? Thank you.
>
> Mark

There are other ways, but I like this one because it is really obvious what you are trying to do.

declare
  l_count number;
begin
  select count(*)
  into l_count
  from people
  where last_name = l_last_name;

  if l_count = 0 then

     do_what_you_wanna_do;
  end if;
end;
/ Received on Thu Jun 06 2002 - 05:39:16 CEST

Original text of this message