Adsense Ad

Thursday, 4 April 2024

How to export table data into CSV file using Oracle Forms Developer.

 

This article would demonstrate how to export table data into CSV file using Oracle Forms Developer.

 

To fulfil this task, you need Oracle Database, Oracle Forms Developer with client libraries installed e.g client_Text_IO. Follow the following steps to run the code given below:

 

1. Create “Location” table in your Oracle database

 Create table Location(

Location_code varchar(20),

state varchar(20),

Location_details varchar(100)

);

 

2. Insert some rows into the table

Insert into Location(‘LHE,’PUJ’,’LAHORE’);

Insert into Location(‘KHI’,’SIN’,’KARACHI’);

 

3. Paste the following code on button pressed trigger in your form. Then compile and run your form.

DECLARE

— File handler

lv_File client_Text_IO.File_Type;

 

 –File Name

lv_File_Name VarChar2(30);

 

 — Timer variable

lv_wait timer;

 

Cursor Load_Rows is

select

v.Location_code||’,’||

v.state||’,’||

v.Location_details data

from Location v;

 

BEGIN

— File Path

 

lv_File_Name := ‘C:\temp\Locations.csv’;

 

–Open file in write mode

lv_File :=  client_text_io.FOpen(lv_File_Name,’W’);

 

— Write header columns

client_text_io.Put_Line(lv_File,’Code,State,Location Name/Details,Locality,Post Code,Output Type,Active?’);

–Write rows into the file

FOR i IN Load_Rows LOOP

   client_text_io.Put_Line(lv_File, i.DATA);

END LOOP;

–Close File

client_text_io.FClose(v_File);

 

–Open file in read mode

lv_File :=  client_text_io.FOpen(lv_File_Name,’R’);

 

–Close file

client_text_io.FClose(lv_File);

lv_wait := create_timer(‘gen_doc’, 2500, NO_REPEAT);

END;

No comments: