Hi,
I need to commit a table after every 300 rows are deleted. This job was done before by a pl/sql script. Now I want it done by a pro*c application. I'm trying to use cursor-for-loop, but I don't know the syntax for the for-loop. I've seen a lot of for(; {....}, but it seems not meet my needs. Any help is greeatly appreciated. mike
-- pl/sql script
EXEC SQL
DECLARE STATUS_CURSOR CURSOR FOR
SELECT str_nbr, rx_nbr -- pk
From tbf0_app_stats
WHERE create_dttm <=
(TO_DATEhost_current_run_dttm, 'YYYYMMDDHH24MISS') -
:host_history_time_factor)
FOR UPDATE;
BEGIN
rowno := 0;
rowdel :=0;
FOR stats_rec IN STATUS_CURSOR ---
LOOP
/* delete the current record */
DELETE FROM tbf0_app_status
WHERE CURRENT OF STATUS_CURSOR;
rowno :=rowno + 1;
if ( rowno == 300)
then
commit;
/* keep the number of rows deleted */
rowdel := rowdel + rowno;
rowno := 0;
end if;
END LOOP;
commit;
rowdel := rowdel + rowno;
DBMS_OUTPUT.NEW_LINE;
DBMS_OUTPUT.PUT_LINE(to_char(rowdel) || ' Records were deleted
bf' || $PART || '_pat_email_address table');
DBMS_OUTPUT.NEW_LINE;
exception
when NO_DATA_FOUND
then
/* record doesn't exist! raise an error to let the call
program know */
raise_application_error(-20000,'Error - No Data found')
when others
then
/* if any other error happened, we have to rollback and
output error message */
rollback;
v_ErrorCode := SQLCODE;
v_ErrorText := SUBSTR(SQLERRM,1,200);
raise_application_error(-20000,v_ErrorCode || '--' || v_
xt);
END;
I need to commit a table after every 300 rows are deleted. This job was done before by a pl/sql script. Now I want it done by a pro*c application. I'm trying to use cursor-for-loop, but I don't know the syntax for the for-loop. I've seen a lot of for(; {....}, but it seems not meet my needs. Any help is greeatly appreciated. mike
-- pl/sql script
EXEC SQL
DECLARE STATUS_CURSOR CURSOR FOR
SELECT str_nbr, rx_nbr -- pk
From tbf0_app_stats
WHERE create_dttm <=
(TO_DATEhost_current_run_dttm, 'YYYYMMDDHH24MISS') -
:host_history_time_factor)
FOR UPDATE;
BEGIN
rowno := 0;
rowdel :=0;
FOR stats_rec IN STATUS_CURSOR ---
LOOP
/* delete the current record */
DELETE FROM tbf0_app_status
WHERE CURRENT OF STATUS_CURSOR;
rowno :=rowno + 1;
if ( rowno == 300)
then
commit;
/* keep the number of rows deleted */
rowdel := rowdel + rowno;
rowno := 0;
end if;
END LOOP;
commit;
rowdel := rowdel + rowno;
DBMS_OUTPUT.NEW_LINE;
DBMS_OUTPUT.PUT_LINE(to_char(rowdel) || ' Records were deleted
bf' || $PART || '_pat_email_address table');
DBMS_OUTPUT.NEW_LINE;
exception
when NO_DATA_FOUND
then
/* record doesn't exist! raise an error to let the call
program know */
raise_application_error(-20000,'Error - No Data found')
when others
then
/* if any other error happened, we have to rollback and
output error message */
rollback;
v_ErrorCode := SQLCODE;
v_ErrorText := SUBSTR(SQLERRM,1,200);
raise_application_error(-20000,v_ErrorCode || '--' || v_
xt);
END;