You can use implicit for loop:
- For your case, it looks suitable to change the two cursors to a single one, using
UNION
(UNION ALL
if you need to process duplicates, or performance reasons), like follows:
FOR aDistinctLine in (
-- first cursor: status <> COMPLETE
SELECT id, ordernum, address FROM order_hist
WHERE status <> 'COMPLETE'
UNION
SELECT id, ordernum, address FROM order_hist_complete
WHERE status = 'COMPLETE'
) LOOP
-- do things with
-- aDistinctLine.id,
-- aDistinctLine.ordernum,
-- aDistinctLine.address
END LOOP;
Then it's better to have status
look like a local variable, e.g. call it l_status
; I had to convince myself it could work to use a plsql variable inside an implicit for loop... guess I learned something today!
declare
l_status varchar2(8) := 'COMPLETE';
begin
for x in (select 'realy?' val from dual where l_status = 'COMPLETE')
loop
dbms_output.put_line(x.val);
end loop;
l_status := 'graby';
for x in (select 'here: not complete' val from dual where l_status <> 'COMPLETE')
loop
dbms_output.put_line(x.val);
end loop;
end;
/