Re: count row function

From: Frank <frankbo_at_interaccess.nl>
Date: Tue, 5 Sep 2000 11:15:33 +0200
Message-ID: <8p2dk7$j1l$1_at_porthos.nl.uu.net>


Hmmm.

Typical inefficient code...
[Quoted] The question you are answering is "how many clients", not "Does this one exist"... Credit due to Steven Feuerstein.

define a cursor, open it, select.
if NO_DATA_FOUND is raised, return 0, else 1

Will use (primary key?) index (if available).

--
Frank
Conan as-if.com> <conan_at_<no-spam> schreef in berichtnieuws
NI1t5.21059$r4.11116_at_news.indigo.ie...

> Hi Sandy,
> select count(*) from a table will always return 1 row regardless of
the
> where clause, so in the case of the situation below the query will return
>
> Count(*)
> _______
> 0
>
> what you can do instead is
> select count(*) into variable from client where clientno='02' and then
have
> PLSQL look at the value of the variable so tour function will look
something
> like this
>
> create or replace function clientidexists(clientid in varchar2 default
'00')
> return boolean
> is
> myrowcount number(10);
> begin
> select count(*) into myrowcount from client where clientno=clientid;
> if myrowcount = 0 then
> return 'false';
> else return 'true';
> end if;
> end ;
>
> hth
>
>
> Sandy wrote in message <1659ac50.4d8c8fed_at_usw-ex0110-076.remarq.com>...
> >hi,
> >
> >I want to know if a client exists in a function. For this I
> >have made a function with a select count... that returns
> >the number of rows of the query : if he exists 1( normally)
> >and if not 0. But doesn't work correctly. What happens
> >when for example a client number '02' doesn't exist in the
> >table client and we do the query :
> >
> >select count(*) from client where client.number='02';
> >
> >thanks
> >
> >sandy
> >
> >
> >* Sent from AltaVista http://www.altavista.com Where you can also find
> related Web Pages, Images, Audios, Videos, News, and Shopping. Smart is
> Beautiful
>
>
Received on Tue Sep 05 2000 - 11:15:33 CEST

Original text of this message