Click to See Complete Forum and Search --> : %rowcount problem


preetham
09-03-2004, 04:14 AM
hi friends

The below procedure is exeecuting properly and displaying 37 records from SQLPLUS.
But the problem is The %rowcount in the procedure is showing only 0(Zero).
can u please help why it is returning 0 instead of 37 .

PROCEDURE p_region(chFlag VARCHAR2 DEFAULT 'C',norecords out number,
pc_Region IN OUT pkg_fe_base_dw.rc_datawindow ) IS
BEGIN
-- v_count := 0;
OPEN pc_Region FOR
SELECT rd_dv_cd,
rd_rg_cd,
rd_rg_sdesc,
rd_rg_ldesc,
nvl(ud_user_name,rd_created_by) rd_created_by,
rd_created_dt,
rd_end_dt, chFlag
FROM rtl_region_def a, rtl_user_Def z
WHERE ((chFlag='C' AND rd_end_dt IS NULL) OR (chFlag='H'))
AND a.rd_created_By = z.ud_user_id (+)
AND nvl(ud_most_recent_flag,'Y')='Y'
ORDER BY rd_rg_cd;
norecords := pc_region%rowcount;
--norecords := 1000;
dbms_output.put_line('no of records:-'|| pc_region%rowcount);
--If pc_region%rowcount = 0 then
--dbms_output.PUT_LINE(pc_region%rowcount);
--else
--bms_output.PUT_LINE('No Records to fetch');
--null;
--end if;
END;
END;
/


Thanks in advance.
preethamnorecords := pc_region%rowcount; 14 ariel

akkerend
09-03-2004, 08:46 AM
This procedure just opens the cursor and does not fetch any record. The%rowcount attribute shows the number of records fetched from the cursor. After opening the cursor and before fetching records it is 0.

preetham
09-07-2004, 03:55 AM
hi
then how can i get the no of records with this procedure.
Regards
suresh

balajiyes
09-07-2004, 04:13 AM
As akkerend rightly pointed out, you need to fetch from the cursor to get the rowcount. You could try something like this:

declare
a varchar2(1) := null;
cursor c is
select * from dual;
BEGIN
open c;
dbms_output.put_line('no of records before fetch statement: '|| c%rowcount);
fetch c into a;
dbms_output.put_line('no of records after fetch statement: '|| c%rowcount);
END;