pls-00225 subprogram or cursor reference is out of scope solution
918286Feb 24 2012 — edited Feb 24 2012Hi ,
Below is my code. i am getting cursor out of scope error. pls provide solution
CREATE OR REPLACE PROCEDURE reconcile_dna
IS
CURSOR dna_host IS SELECT * FROM t_dna_stage;
dna_host_cur dna_host%rowtype;
CURSOR server_host IS SELECT * FROM t_servers WHERE rec_flag = 'N';
server_host_rec server_host%rowtype;
vhostserver_cnt NUMBER := 0;
vhost_cnt NUMBER := 0;
vhostdna_cnt NUMBER := 0;
vserver_cnt NUMBER := 0;
BEGIN
DBMS_OUTPUT.put_line ('******Reconciliation Started******');
UPDATE t_servers
SET rec_flag = 'N';
-- Updating t_servers table to set rec_flag='N' before starting the reconciliation process
BEGIN
DBMS_OUTPUT.put_line ('******Inside Reconciliation ******');
OPEN dna_host;
LOOP
FETCH dna_host INTO dna_host_cur;
EXIT WHEN dna_host%NOTFOUND;
SELECT COUNT (*) -- searching in t_server table
INTO vhost_cnt
FROM t_servers
WHERE LOWER (hostname) = LOWER (dna_host_cur.hostname);
IF vhost_cnt > 0
THEN
UPDATE t_servers
-- Updating t_server table if hostname found in dna data
SET rec_flag = 'Y'
WHERE LOWER (hostname) = LOWER (dna_host_cur.hostname);
SELECT COUNT (*)
-- searching in t_dna_defects table for reconciled hostnames
INTO vhostserver_cnt
FROM t_dna_defects
WHERE LOWER (hostname) = LOWER (dna_host_cur.hostname);
IF vhostserver_cnt > 0
THEN
UPDATE t_dna_defects
-- Updating t_dna_defects table when hostname reconciled in t_servers
SET remediate_date = SYSDATE,
active = 'N',
last_update_by = '502061473',
last_update_date = SYSDATE
WHERE LOWER (hostname) = LOWER (dna_host_cur.hostname);
END IF;
ELSE
SELECT COUNT (*)
-- searching in t_dna_defects table if hostname notfound in t_server table
INTO vhostdna_cnt
FROM t_dna_defects
WHERE LOWER (hostname) = LOWER (dna_host_cur.hostname);
IF vhostdna_cnt > 0
THEN
UPDATE t_dna_defects
-- Updating t_dna_defects table when hostname found in t_dna_defects
SET COUNT = COUNT + 1,
last_found_date = SYSDATE,
last_update_by = '502061473',
last_update_date = SYSDATE,
active='Y'
WHERE LOWER (hostname) = LOWER (dna_host_cur.hostname);
ELSE
INSERT INTO t_dna_defects
-- Inserting hostname information record in t_dna_defects table when not found in t_server and t_dna_defects
( reconcile_id, hostname,
os, ip_address, business,
business_unit,
reporting_business_unit,
userid, city,
state, country, active, COUNT,
first_found_date, last_found_date,
created_by, creation_date
)
VALUES (recon_id_seq.NEXTVAL, dna_host_cur.hostname,
dna_host_cur.os, dna_host_cur.ip, dna_host_cur.business,
dna_host_cur.businessunit,
dna_host_cur.reportingbusinessunit,
dna_host_cur.userid, dna_host_cur.city,
dna_host_cur.state, dna_host_cur.country, 'Y', 1,
SYSDATE, SYSDATE,
'502061473', SYSDATE
);
END IF;
END IF;
END LOOP;
close dna_host;
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.put_line ('In Exception step 1 ERROR IS'||SQLCODE||' '||SQLERRM);
END;
BEGIN
DBMS_OUTPUT.put_line ('************Reconciliation step 2******');
OPEN server_host;
LOOP
FETCH server_host INTO server_host_rec;
EXIT WHEN server_host%NOTFOUND;
SELECT COUNT (*)
INTO vserver_cnt
FROM t_server_defects
WHERE LOWER (hostname) = LOWER (server_host_rec.hostname);
IF vserver_cnt > 0
THEN
UPDATE t_server_defects
SET last_found_date = SYSDATE,
COUNT = COUNT + 1,
ACTIVE='Y';
ELSE
INSERT INTO t_server_defects
(reconcile_id, hostname, active,
first_found_date, last_found_date, remediate_date
)
VALUES (recon_id_seq.NEXTVAL, server_host_rec.hostname, 'Y',
SYSDATE, SYSDATE, NULL
);
END IF;
END LOOP;
CLOSE server_host;
UPDATE t_server_defects
SET ACTIVE='N'
where trunc(last_found_date)<>trunc(sysdate);
EXCEPTION
WHEN OTHERS
THEN
DBMS_OUTPUT.put_line ('****Inside exception for step 2******');
DBMS_OUTPUT.put_line ('ERROR IS'||SQLCODE||' '||SQLERRM);
END;
COMMIT;
END;
Regards,
Tiru