|
-----Original Message-----
From: RPG400-L [mailto:rpg400-l-bounces@xxxxxxxxxxxx] On Behalf Of Vernon
Hamberg
Sent: Monday, September 14, 2015 5:18 PM
To: RPG programming on the IBM i (AS/400 and iSeries)
Subject: Re: RPG400-L Digest, Vol 14, Issue 336
Marvin
I thought this was an estimate only for the OPEN - much the same as
SQLERRD(3) which is documented like this for the PREPARE -
For the PREPARE statement, contains the estimated number of rows
selected. If the number of rows is greater than 2 147 483 647, then 2
147 483 647 is returned.
There've been other threads about this, and I think it has been said the
only sure way to get row count is SELECT COUNT(*) FROM TABLE
Now I'm very happy to be mistaken here, because I'd love to have the
simple answer from time to time, the SQLERRD(3) answer. Or the GET
DIAGNOSTICS answer - oh, that array element IS updated with the number or
rows retrieved with FETCH - useful for multiple-row fetches.
I do see that the documentation for DB2_NUMBER_ROWS says it IS the number
of rows after an OPEN or FETCH, but with a SENSITIVE cursor it is an
estimate. I see that default for SENSITIVE on a cursor is ASENSITIVE, so
that what you get depends.
Any takers on whether the GET DIAGNOSTICS value is reliable for managing a
loop? Under what conditions?
Regards
Vern
On 9/14/2015 2:43 PM, Marvin Radding wrote:
Mitch,provide the total number of records in the data set after the open. That
There is one method that would be a short cut. GET DIAGNOSTICs can
can control the number of records fetched in the FETCH INTO statement.
http://www.itjungle.com/fhg/fhg052009-story01.html
After the open you can code:
/exec sql
GET DIAGNOSTICS :row_count = DB2_NUMER_ROWS; /end
Marvin
------------------------------
message: 8
date: Mon, 14 Sep 2015 18:17:00 +0000 (UTC)
from: Mitch Gallman <qtemp@xxxxxxx>
subject: Re: Loading arrayDS from sql select into statement?
I've used the following article several times as a reference:
I've never had to do a select count prior to doing the fetch.<mkoester@xxxxxxxxxxxxx> wrote:
Mitch
On Monday, September 14, 2015 1:58 PM, "Koester, Michael"
declaring and opening a cursor, I can successfully use
Charles,
Would be nice if you could use SELECT INTO along with FETCH FIRST XXAfter getting the count (select count(*) into :resultCount from...), and
ROWS...
? ? exec sql
? ? fetch MyCursor for :resultCount rows
? ? ? into :ArrayDS;
? ? ? ? ? ? ? ? ? ? ? ?
But there apparently are no shorter shortcuts.
Michael Koester
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.