Re: Assigning SELECT COUNT to a variable in a procedure

From: Aparna Joshi <joshi_aparna_at_yahoo.com>
Date: Wed, 8 Nov 2000 23:18:20 +0800
Message-ID: <3a097a8f.0_at_news.tm.net.my>


Hi Torgeir,

You could try this....

Declare

        EntryCoun Number;
Begin

        Select Count (join1) Into EntryCoun From Hr Where join1 = join;
        do what ever u need to do with the value stored in EntryCoun
End;
/

Using a cursor you could try...

Declare

        Cursor CrEntry Is
                Select empno, join1 Into EntryCoun From Hr Where join1 =
join;
        EntryCoun Number;
Begin
        EntryCoun := 0;
        For CrRowEntry In CrEntry
        Loop
            EntryCoun := EntryCoun + 1;
        End Loop;
        do what ever u need to do with the value stored in EntryCoun
End;
/

Of course I assume that the SQL statement Select Count (join1) From Hr Where join1 = join; is correct and working at the SQL prompt....

Hope this helps...

Regards,
Aparna
Torgeir Pedersen <torgeir.pedersen_at_maxware.com> wrote in message news:8u5c2d$j6c$1_at_bob.news.rcn.net...
> I am trying to check how many records in a database match a query and do
> something with it, but I cant find the syntax. I have tried select.
> -- EntryCount = select count (Join1) from hr where Join1 = Join;
> -- select count (Join1) from hr where Join1 = Join INTO EntryCount;
> But none of them are working
>
> I have also tried a Cursor For Loop which count the entries
>
> CURSOR Counter IS
> SELECT Empno, Join1 from HR WHERE Join1 = Join;
> BEGIN
> EntryCount := 0
> FOR V_ROW IN Counter LOOP
> EntryCount := EntryCount + 1;
> END LOOP;
>
> But this doesn't work either.
>
> Does anybody have a tip on a simple way of assigning count to a variable
 in
> a Procedure
>
> --
>
> Torgeir Pedersen
> mailto: torgeir.pedersen_at_maxware.com
>
>
>
Received on Wed Nov 08 2000 - 16:18:20 CET

Original text of this message