PL*SQL - Oracle 8i - Setting result of count(*) to a variable?

Hello.

Is there a way of setting the value of "select count(*)..." to a variable in PL*SQL?
LVL 22
Adam LeinssAsked:
Who is Participating?
 
pagerbakConnect With a Mentor Commented:
Hi

Here's a small procedure that show both "select into ..." and a cursor solution

CREATE OR REPLACE PROCEDURE test IS
cnt NUMBER;

CURSOR c IS
   SELECT COUNT(*) cnt
     FROM USER_TABLES;

BEGIN
   SELECT COUNT(*)
     INTO cnt
     FROM USER_TABLES;
   dbms_output.PUT_LINE('cnt=' || TO_CHAR(cnt));
   
   FOR ROW IN c LOOP
       cnt := ROW.cnt;
   END LOOP;  
   dbms_output.PUT_LINE('cnt=' || TO_CHAR(cnt));

END test;
/

regards pagerbak
0
All Courses

From novice to tech pro — start learning today.