Oracle - REGISTROS DE UN CURSOR

 
Vista:

REGISTROS DE UN CURSOR

Publicado por ALEJANDRO (1 intervención) el 08/07/2005 18:23:27
¿COMO SE PUEDE SABER EL NUMERO DE REGISTROS DE UN CURSOR.. SIN RECORRERLO?

GRACIAS.
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

RE:REGISTROS DE UN CURSOR

Publicado por JSL (186 intervenciones) el 16/07/2005 00:16:21
%ROWCOUNT

This is a cursor attribute, which can be appended to the name of a cursor or cursor variable. When a cursor is opened, %ROWCOUNT is zeroed. Before the first fetch, cursor_name%ROWCOUNT yields 0. Thereafter, it yields the number of rows fetched so far. The number is incremented if the latest fetch returned a row.

Until a SQL statement is executed, SQL%ROWCOUNT yields NULL. Thereafter, it yields the number of rows affected by the statement. SQL%ROWCOUNT yields 0 if the statement affected no rows.

The following PL/SQL block uses %ROWCOUNT to fetch the names and salaries of the five highest-paid employees:

-- available online in file 'examp14'
DECLARE
CURSOR c1 is
SELECT ename, empno, sal FROM emp
ORDER BY sal DESC; -- start with highest-paid employee
my_ename CHAR(10);
my_empno NUMBER(4);
my_sal NUMBER(7,2);
BEGIN
OPEN c1;
LOOP
FETCH c1 INTO my_ename, my_empno, my_sal;
EXIT WHEN (c1%ROWCOUNT > 5) OR (c1%NOTFOUND);
INSERT INTO temp VALUES (my_sal, my_empno, my_ename);
COMMIT;
END LOOP;
CLOSE c1;
END;
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
-2
Comentar

RE:REGISTROS DE UN CURSOR

Publicado por carla (1 intervención) el 25/05/2016 17:36:04
No respondes a la pregunta, simplemente explicas como se usa el atributo rowcount, la pregunta es si se puede conocer el numero de rows de un cursor sin tener que recorrerlo y en tu ejemplo lo recorres

Muy buena la explicación pero no se responde a la pregunta solicitada
la respuesta sería si ---> ejemplo
o no, explicando que la opcion que se da es la que tu explicas o decir que No hay manera de saber de forma "directa" cuantos registros tiene el cursor, aunque se puede hacer un count sobre la misma select sí se desea saber la cantidad de registros.

Saludos
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
Imágen de perfil de Elvis
Val: 209
Plata
Ha mantenido su posición en Oracle (en relación al último mes)
Gráfica de Oracle

RE:REGISTROS DE UN CURSOR

Publicado por Elvis (102 intervenciones) el 25/05/2016 20:36:26
Hasta donde se igual necesitas hacer un cursor implícito Ej.

Open Cursor;
Fetch Cursor;
dbms_out.put_line (Cursor%ROWCOUNT);
close Cursor;

Te debe de devolver las tuplas devueltas del cursor que tienen datos o sino te devuelve 0;

No necesariamente lo recorres con un Loop
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
-1
Comentar

RE:REGISTROS DE UN CURSOR

Publicado por Miguel Moreno (1 intervención) el 27/01/2019 00:13:04
Otra opción es usar la instrucción bulk collect

DECLARE
CURSOR c1 is
SELECT ename, empno, sal FROM emp
ORDER BY sal DESC; -- start with highest-paid employee

type tyCur is table of c1%rowtype;
tbCur tyCur;

BEGIN
OPEN c1;
FETCH c1 bulk collect INTO tbCur;
close c1;

if tbCur.count > 0 then
dbms_output.put_line('filas '||tbCur.count );
end if;

END;
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar