Declare
out_file text_io.file_type;
v_line varchar2(1000);
begin
out_file := text_io.fopen(‘C:\job_history.csv‘, ‘w‘);
go_block(‘job_history‘);
-- move control to first record;
first_record;
loop
v_line := :job_history.employee_id||‘,‘|| :job_history.start_date||‘,‘|| :job_history.end_date ||‘,‘||
:job_history.job_id||‘,‘|| :job_history.department_id;
text_io.put_line(out_file, v_line);
-- move control to next record;
if :system.last_record = ‘TRUE‘ then
exit;
end if;
next_record;
end loop;
text_io.fclose(out_file);
-- again after completion move control to first record
first_record;
end;