The example given below for writing text file or CSV using Text_IO package from a tabular block in Oracle Forms. 

Suppose there is a tabular grid data block "Job_History" in your forms and you want to write a CSV on click of a button by reading whole block from top to bottom. The following is the demo screen shot:


You can also download this form from this link Job_History_Csv.fmb.

Write the following When-Button-Pressed trigger code for the "Export To CSV" button:

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;

Ask Your Questions By Comment Below.

Write csv files from data block in Oracle forms.

Post a Comment

More Topics

V. Kapoor

{picture#https://3.bp.blogspot.com/-q3wCssWUHo8/ViDFfCpPEuI/AAAAAAAAD0M/MHPvgnl3T3U/s1600/authpic.JPG} Vinish Kapoor is a Software Consultant, currently working in a reputed IT company in Noida, India and doing blogging on Oracle Forms, SQL and PLSQL topics. He is an author of an eBook Oracle Forms Recipes, which is available on Google play. {facebook#https://www.facebook.com/foxinfotech2014} {twitter#https://twitter.com/foxinfotech} {google#https://plus.google.com/u/0/+VKapoor/posts}
Fox Infotech. Powered by Blogger.