Determinar el número de filas en la tabla de resultados para un cursor desplazable estático
Puede determinar cuántas filas hay en la tabla de resultados de un cursor desplazable INSENSITIVE o SENSITIVE STATIC.
Procedimiento
Para determinar el número de filas de la tabla de resultados para un cursor estático desplazable, siga estos pasos:
Ejemplo
El siguiente código en lenguaje C muestra cómo obtener el número de filas en una tabla de resultados de un cursor estático sensible.
EXEC SQL INCLUDE SQLCA;
long int rowcount;
EXEC SQL
DECLARE SENSTAT SENSITIVE STATIC SCROLL CURSOR FOR
SELECT * FROM EMP;
EXEC SQL OPEN SENSTAT;
if (SQLCODE==0) {
EXEC SQL FETCH AFTER SENSTAT; /* Position the cursor after the end */
/* of the result table */
if (SQLCODE==0) {
/************************************/
/* Get the row count from the SQLCA */
/************************************/
printf("%s \n","Row count from SQLCA: ");
printf("%s %d\n","SQLERRD1: High-order word: ",sqlca.sqlerrd[0]);
/* Get the high-order word of the */
/* result table size */
printf("%s %d\n","SQLERRD2: Low-order word: ",sqlca.sqlerrd[1]);
/* Get the low-order word of the */
/* result table size */
/******************************************/
/* Get the row count from GET DIAGNOSTICS */
/******************************************/
EXEC SQL GET DIAGNOSTICS :rowcount = DB2_NUMBER_ROWS;
if (SQLCODE==0) {
printf("%s %d\n","Row count from GET DIAGNOSTICS: ",rowcount);
}
}
}