Monday, January 10, 2022

How to Export Oracle data to Excel file from Oracle Forms

How to Export Oracle data to Excel file from Oracle Forms

 Step 1:

Create a button with any name and then click F11 to create a trigger called "WHEN-BUTTON-PRESSED"

How to Export Oracle data to Excel file from Oracle Forms

Step 2:

Put all of the code listed below in the when-button-pressed trigger.

DECLARE

                  in_file   Text_IO.File_Type;

  linebuf   VARCHAR2(4000);

  filename  VARCHAR2(4000);

  vr_rowcount number(3);

BEGIN

                GO_BLOCK('emp');

                FIRST_RECORD;

  filename:=  Get_File_Name(Null,Null,'CSV Files (*.csv)|*.csv|',Null,SAVE_FILE);

  in_file := Text_IO.Fopen(filename, 'w');

 

  linebuf :=           '"'||'Empno'||'","'||

                                                                                                                'Ename'||'","'||

                                                                                                                'job'||'","'||

                                                                                                                'MGR'||'","'||

                                                                                                                                'Hiredate'||'","'||

                                                                                                                                'sal'||'","'||

                                                                                                                                'comm'||'","'||

                                                                                                                                'Deptno'||'"';

                                                                                                                               

                                                                                                                               

                                Text_IO.put_Line(in_file, linebuf);

  LOOP

                vr_rowcount := vr_rowcount + 1;

                linebuf :=             '"'||:emp.empno||'","'||

                                                :emp.ename||'","'||

                                                                :emp.job||'","'||

                                                                :emp.mgr||'","'||

                                                                :emp.hiredate||'","'||

                                                                :emp.sal||'","'||

                                                                :emp.comm||'","'||

                                                                :emp.deptno||'"';

                                                                                                                               

                                                                                                                               

                                Text_IO.put_Line(in_file, linebuf);

    Text_IO.New_Line;

 EXIT WHEN :SYSTEM.LAST_RECORD = 'TRUE';

 NEXT_RECORD;

  END LOOP;

      Text_IO.Fclose(in_file);

END;

Step 3:

Run the form and press the button you created. After clicking the button it’s show the dialog box enter the path where you save the file and put the file and save it.

How to Export Oracle data to Excel file from Oracle Forms



Output:

How to Export Oracle data to Excel file from Oracle Forms


0 comments:

Post a Comment

If you have any doubts, please let me know. I will help you.