sql%rowcount returns rows more than table count
RNFeb 25 2010 — edited Feb 25 2010Please look at this code:
DECLARE
CURSOR c1 IS SELECT state_id, state_name, license_nbr FROM states st, licenses lic
WHERE st.license_id =lic.license_id;
TYPE reg_t IS TABLE OF c1%ROWTYPE;
v_array reg_t;
BEGIN
OPEN c1;
LOOP
FETCH c1 BULK COLLECT INTO v_array ;
FORALL i IN v_array.FIRST .. v_array.LAST
UPDATE st_lic sl
SET state_id = v_array(i).state_id,
state_name = v_array(i).state_name
WHERE sl.license_nbr = v_array(i).license_nbr;
EXIT WHEN c1%NOTFOUND;
END LOOP;
CLOSE c1;
DBMS_OUTPUT.PUT_LINE('count is :' ||SQL%ROWCOUNT);
END;
For table "states" state_id is primary key. Each state_id has one and only one license_id.
For table "licenses", license_id is the primary key and license_nbr is not null and unique.
For table "st_lic", license_nbr is not null field and same license_nbr may occur more than once.
Question is : sql%rowcount returns count which is more than the total number of rows in table st_lic. Is possible? If ues, how? I don't see anything wrong with the query.
Thanks for the help!
Edited by: user5406804 on Feb 25, 2010 5:57 AM