Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.misc -> Getting only limited number of rows
Hi,
Does anyone know if it's possible to limit the number of rows returned using Dynamic SQL? It was shown how this was possible in a previous post using a static cursor.
>DECLARE
> CURSOR C1 IS
> SELECT SALESPERSON, SUM(SALES) SALES
> FROM SALES
> GROUP BY SALESPERSON
> ORDER BY SUM(SALES) DESC;
> W1 C1%ROWTYPE;
> I NUMBER := 0;
>BEGIN
> OPEN C1;
> DBMS_OUTPUT.PUT_LINE('TOP 10 SALESPERSONS');
> LOOP
> FETCH C1 INTO W1;
> EXIT WHEN C1%NOTFOUND OR I >= 10;
> DBMS_OUTPUT.PUT(W1.SALESPERSON);
> DBMS_OUTPUT.PUT_LINE(to_char(w1.sales,' 999,999,999.99'));
> I := I + 1;
> END LOOP;
> CLOSE C1;
>END;
Thanks,
Larry
-----------== Posted via Deja News, The Discussion Network ==---------- http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own Received on Fri Mar 19 1999 - 08:49:02 CST
![]() |
![]() |