Sybase NNTP forums - End Of Life (EOL)

The NNTP forums from Sybase - forums.sybase.com - are now closed.

All new questions should be directed to the appropriate forum at the SAP Community Network (SCN).

Individual products have links to the respective forums on SCN, or you can go to SCN and search for your product in the search box (upper right corner) to find your specific developer center.

@@Rowcount does not work in cursor

7 posts in General Discussion Last posting was on 2011-01-17 13:36:19.0Z
Michaël Sleeuwagen Posted on 2011-01-14 16:01:53.0Z
From: "Michaël Sleeuwagen" <michael.sleeuwagen@jandenul.com>
Newsgroups: ianywhere.public.general
Subject: @@Rowcount does not work in cursor
Lines: 37
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.5931
X-RFC2646: Format=Flowed; Original
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5994
NNTP-Posting-Host: vip152.sybase.com
X-Original-NNTP-Posting-Host: vip152.sybase.com
Message-ID: <4d307371$1@forums-1-dub>
Date: 14 Jan 2011 08:01:53 -0800
X-Trace: forums-1-dub 1295020913 10.22.241.152 (14 Jan 2011 08:01:53 -0800)
X-Original-Trace: 14 Jan 2011 08:01:53 -0800, vip152.sybase.com
Path: forums-1-dub!not-for-mail
Xref: forums-1-dub ianywhere.public.general:8114
Article PK: 7134

Hi,

I want to see the amount of records returned by the cursor and I would like
to use the @@rowcount global variable, so I don't have to perform an extra
query for it.
But the problem is that @@rowcount always returns always 0.
My cursor looks something like this:

begin
declare cur_test cursor for select * from epos.parameter;
declare test numeric(16);
open cur_test;
lp: loop
case @@rowcount
when 0 then ......(no query is executed here)
end case;
end loop;
close cur_test;
end;

select * from epos.parameter returns 57 rows

Does anybody have an idea why @@rowcount gives me the wrong value?
I found the following in the help file:

With cursors, @@rowcount represents the cumulative number of rows returned
from the cursor result set to the client, up to the last fetch request.

So if I understand it correctly, the @@rowcount should keep the amount of
records of the cursor until the end of the cursor is reached? Why doesn't
this work then?

Thanks,
Michaël


R. Pods Posted on 2011-01-14 17:08:44.0Z
From: "R. Pods" <r.pods@gmx.net>
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.2.13) Gecko/20101207 Thunderbird/3.1.7
MIME-Version: 1.0
Newsgroups: ianywhere.public.general
Subject: Re: @@Rowcount does not work in cursor
References: <4d307371$1@forums-1-dub>
In-Reply-To: <4d307371$1@forums-1-dub>
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 8bit
NNTP-Posting-Host: vip152.sybase.com
X-Original-NNTP-Posting-Host: vip152.sybase.com
Message-ID: <4d30831c$1@forums-1-dub>
Date: 14 Jan 2011 09:08:44 -0800
X-Trace: forums-1-dub 1295024924 10.22.241.152 (14 Jan 2011 09:08:44 -0800)
X-Original-Trace: 14 Jan 2011 09:08:44 -0800, vip152.sybase.com
Lines: 52
Path: forums-1-dub!not-for-mail
Xref: forums-1-dub ianywhere.public.general:8115
Article PK: 7132

Michaël,

From the docs on @@rowcount:
With cursors, @@rowcount represents the cumulative number of rows
returned from the cursor result set to the client, up to the last fetch
request.

Iif I understand that correctly, it means @@rowcount will stay 0 if your
loop doesn't actually fetch any records.

Cheers
Reimer

Michaël Sleeuwagen wrote:
> Hi,
>
> I want to see the amount of records returned by the cursor and I would like
> to use the @@rowcount global variable, so I don't have to perform an extra
> query for it.
> But the problem is that @@rowcount always returns always 0.
> My cursor looks something like this:
>
> begin
> declare cur_test cursor for select * from epos.parameter;
> declare test numeric(16);
> open cur_test;
> lp: loop
> case @@rowcount
> when 0 then ......(no query is executed here)
> end case;
> end loop;
> close cur_test;
> end;
>
> select * from epos.parameter returns 57 rows
>
> Does anybody have an idea why @@rowcount gives me the wrong value?
> I found the following in the help file:
>
> With cursors, @@rowcount represents the cumulative number of rows returned
> from the cursor result set to the client, up to the last fetch request.
>
> So if I understand it correctly, the @@rowcount should keep the amount of
> records of the cursor until the end of the cursor is reached? Why doesn't
> this work then?
>
> Thanks,
> Michaël
>
>
>


Michaël Sleeuwagen Posted on 2011-01-17 07:23:54.0Z
From: "Michaël Sleeuwagen" <michael.sleeuwagen@jandenul.com>
Newsgroups: ianywhere.public.general
References: <4d307371$1@forums-1-dub> <4d30831c$1@forums-1-dub>
Subject: Re: @@Rowcount does not work in cursor
Lines: 64
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.5931
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5994
X-RFC2646: Format=Flowed; Response
NNTP-Posting-Host: vip152.sybase.com
X-Original-NNTP-Posting-Host: vip152.sybase.com
Message-ID: <4d33ee8a$1@forums-1-dub>
Date: 16 Jan 2011 23:23:54 -0800
X-Trace: forums-1-dub 1295249034 10.22.241.152 (16 Jan 2011 23:23:54 -0800)
X-Original-Trace: 16 Jan 2011 23:23:54 -0800, vip152.sybase.com
Path: forums-1-dub!not-for-mail
Xref: forums-1-dub ianywhere.public.general:8116
Article PK: 7138

I don't think that is what they mean. As I understand it, @@rowcount
represents the number of rows that are in the cursor. But this doesn't seem
to work. Any other ideas? Or is there an other global variable that I can
use to check the recordcount of the cursor?

Kind Regards,
Michaël

"R. Pods" <r.pods@gmx.net> wrote in message news:4d30831c$1@forums-1-dub...
> Michaël,
>
> From the docs on @@rowcount:
> With cursors, @@rowcount represents the cumulative number of rows returned
> from the cursor result set to the client, up to the last fetch request.
>
> Iif I understand that correctly, it means @@rowcount will stay 0 if your
> loop doesn't actually fetch any records.
>
> Cheers
> Reimer
>
> Michaël Sleeuwagen wrote:
>> Hi,
>>
>> I want to see the amount of records returned by the cursor and I would
>> like
>> to use the @@rowcount global variable, so I don't have to perform an
>> extra
>> query for it.
>> But the problem is that @@rowcount always returns always 0.
>> My cursor looks something like this:
>>
>> begin
>> declare cur_test cursor for select * from epos.parameter;
>> declare test numeric(16);
>> open cur_test;
>> lp: loop
>> case @@rowcount
>> when 0 then ......(no query is executed here)
>> end case;
>> end loop;
>> close cur_test;
>> end;
>>
>> select * from epos.parameter returns 57 rows
>>
>> Does anybody have an idea why @@rowcount gives me the wrong value?
>> I found the following in the help file:
>>
>> With cursors, @@rowcount represents the cumulative number of rows
>> returned
>> from the cursor result set to the client, up to the last fetch request.
>>
>> So if I understand it correctly, the @@rowcount should keep the amount of
>> records of the cursor until the end of the cursor is reached? Why doesn't
>> this work then?
>>
>> Thanks,
>> Michaël
>>
>>
>>
>


Krisztián Pintér Posted on 2011-01-17 08:48:37.0Z
Content-Type: text/plain; charset=iso-8859-2; format=flowed; delsp=yes
Newsgroups: ianywhere.public.general
Subject: Re: @@Rowcount does not work in cursor
References: <4d307371$1@forums-1-dub> <4d30831c$1@forums-1-dub> <4d33ee8a$1@forums-1-dub>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
From: Krisztián Pintér <pinter.krisztian@karatnet.hu>
Organization: KarátNet Kft
Message-ID: <op.vpf2ra15jxfpn7@karhuwst-pint.karatnet.hu>
User-Agent: Opera Mail/11.00 (Win32)
NNTP-Posting-Host: vip152.sybase.com
X-Original-NNTP-Posting-Host: vip152.sybase.com
Date: 17 Jan 2011 00:48:37 -0800
X-Trace: forums-1-dub 1295254117 10.22.241.152 (17 Jan 2011 00:48:37 -0800)
X-Original-Trace: 17 Jan 2011 00:48:37 -0800, vip152.sybase.com
Lines: 9
Path: forums-1-dub!not-for-mail
Xref: forums-1-dub ianywhere.public.general:8117
Article PK: 7136

On Mon, 17 Jan 2011 08:23:54 +0100, MichaĂŤl Sleeuwagen

<michael.sleeuwagen@jandenul.com> wrote:

> As I understand it, @@rowcount
> represents the number of rows that are in the cursor.

there is no such thing as "rows in the cursor". in general, the server
has no idea how many rows you can fetch, not to mention it can change
in time.


Michaël Sleeuwagen Posted on 2011-01-17 09:23:13.0Z
From: "Michaël Sleeuwagen" <michael.sleeuwagen@jandenul.com>
Newsgroups: ianywhere.public.general
References: <4d307371$1@forums-1-dub> <4d30831c$1@forums-1-dub> <4d33ee8a$1@forums-1-dub> <op.vpf2ra15jxfpn7@karhuwst-pint.karatnet.hu>
Subject: Re: @@Rowcount does not work in cursor
Lines: 21
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.5931
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5994
X-RFC2646: Format=Flowed; Response
NNTP-Posting-Host: vip152.sybase.com
X-Original-NNTP-Posting-Host: vip152.sybase.com
Message-ID: <4d340a81@forums-1-dub>
Date: 17 Jan 2011 01:23:13 -0800
X-Trace: forums-1-dub 1295256193 10.22.241.152 (17 Jan 2011 01:23:13 -0800)
X-Original-Trace: 17 Jan 2011 01:23:13 -0800, vip152.sybase.com
Path: forums-1-dub!not-for-mail
Xref: forums-1-dub ianywhere.public.general:8118
Article PK: 7137

This is what the help file says: With cursors, @@rowcount represents the
cumulative number of rows
returned from the cursor result set to the client, up to the last fetch.
What does this mean then?

Thanks,
Michaël

"Krisztián Pintér" <pinter.krisztian@karatnet.hu> wrote in message
news:op.vpf2ra15jxfpn7@karhuwst-pint.karatnet.hu...
> On Mon, 17 Jan 2011 08:23:54 +0100, Michaël Sleeuwagen
> <michael.sleeuwagen@jandenul.com> wrote:
>
>> As I understand it, @@rowcount
>> represents the number of rows that are in the cursor.
>
> there is no such thing as "rows in the cursor". in general, the server
> has no idea how many rows you can fetch, not to mention it can change
> in time.


David Kerber <ns_dkerber Posted on 2011-01-17 13:20:14.0Z
From: David Kerber <ns_dkerber@ns_warrenrogersassociates.com>
Newsgroups: ianywhere.public.general
Subject: Re: @@Rowcount does not work in cursor
Message-ID: <MPG.279e0c157134f52e9896ee@forums.sybase.com>
References: <4d307371$1@forums-1-dub> <4d30831c$1@forums-1-dub> <4d33ee8a$1@forums-1-dub> <op.vpf2ra15jxfpn7@karhuwst-pint.karatnet.hu> <4d340a81@forums-1-dub>
Organization: Warren Rogers Associates
MIME-Version: 1.0
Content-Type: text/plain; charset="iso-8859-15"
Content-Transfer-Encoding: 8bit
User-Agent: MicroPlanet-Gravity/2.9.15
NNTP-Posting-Host: vip152.sybase.com
X-Original-NNTP-Posting-Host: vip152.sybase.com
Date: 17 Jan 2011 05:20:14 -0800
X-Trace: forums-1-dub 1295270414 10.22.241.152 (17 Jan 2011 05:20:14 -0800)
X-Original-Trace: 17 Jan 2011 05:20:14 -0800, vip152.sybase.com
Lines: 27
Path: forums-1-dub!not-for-mail
Xref: forums-1-dub ianywhere.public.general:8119
Article PK: 7139

In article <4d340a81@forums-1-dub>, michael.sleeuwagen@jandenul.com
says...

>
> This is what the help file says: With cursors, @@rowcount represents the
> cumulative number of rows
> returned from the cursor result set to the client, up to the last fetch.
> What does this mean then?

It tells you how many you have retrieved. What he was saying is that
you can't tell ahead of time how many you are going to be able retrieve.

>
> Thanks,
> Michaël
> "Krisztián Pintér" <pinter.krisztian@karatnet.hu> wrote in message
> news:op.vpf2ra15jxfpn7@karhuwst-pint.karatnet.hu...
> > On Mon, 17 Jan 2011 08:23:54 +0100, Michaël Sleeuwagen
> > <michael.sleeuwagen@jandenul.com> wrote:
> >
> >> As I understand it, @@rowcount
> >> represents the number of rows that are in the cursor.
> >
> > there is no such thing as "rows in the cursor". in general, the server
> > has no idea how many rows you can fetch, not to mention it can change
> > in time.


Krisztián Pintér Posted on 2011-01-17 13:36:19.0Z
Content-Type: text/plain; charset=iso-8859-2; format=flowed; delsp=yes
Newsgroups: ianywhere.public.general
Subject: Re: @@Rowcount does not work in cursor
References: <4d307371$1@forums-1-dub> <4d30831c$1@forums-1-dub> <4d33ee8a$1@forums-1-dub> <op.vpf2ra15jxfpn7@karhuwst-pint.karatnet.hu> <4d340a81@forums-1-dub>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
From: Krisztián Pintér <pinter.krisztian@karatnet.hu>
Organization: KarátNet Kft
Message-ID: <op.vpgf2sr1jxfpn7@karhuwst-pint.karatnet.hu>
User-Agent: Opera Mail/11.00 (Win32)
NNTP-Posting-Host: vip152.sybase.com
X-Original-NNTP-Posting-Host: vip152.sybase.com
Date: 17 Jan 2011 05:36:19 -0800
X-Trace: forums-1-dub 1295271379 10.22.241.152 (17 Jan 2011 05:36:19 -0800)
X-Original-Trace: 17 Jan 2011 05:36:19 -0800, vip152.sybase.com
Lines: 22
Path: forums-1-dub!not-for-mail
Xref: forums-1-dub ianywhere.public.general:8120
Article PK: 7140

On Mon, 17 Jan 2011 10:23:13 +0100, MichaĂŤl Sleeuwagen

<michael.sleeuwagen@jandenul.com> wrote:

> cumulative number of rows
> returned from the cursor result set to the client, up to the last fetch.
> What does this mean then?

rows returned is synonymous to rows fetched

easiest example would be

select * from bigtable where nonindexedcolumn = 6

it will issue a full table scan, and will happily return the first
row without counting all the matching rows. if the circumstances
allow, the cursor might be dynamic, which means that if you insert new
rows to the table before the fetching arrives at that part, it will
be included. also possible that you get different rows when you step
back. and yet again different rows when you step forward again. there
is no fixed rowset behind a cursor, at least not always. you have some
control over this behaviour, with cursor types. but still, sybase will
not count the rows for you beforehand.