Introduction: –
This document is about how to download data from the table in text format using PL/SQL in Oracle APEX.
The following technologies have been used to download data from the table in text format using PL/SQL in Oracle APEX.
- PL/SQL
- Oracle APEX
Why we need to do: –
If the requirement arises to download the data from the table in text format as comma separated values, we can use this method to download as text document on button click behavior.
How do we solve:
The following steps will help to download data in text format using Oracle APEX,
Step 1: Create new application process to globally call the process with in the application.
Code:
BEGIN
— Set the MIME type
owa_util.mime_header(‘application/octet’, FALSE );
— Set the name of the file
htp.p(‘Content-Disposition: attachment; filename=”gc_check_format.txt”‘);
— Close the HTTP Header
owa_util.http_header_close;
— Loop through all rows in EMP
FOR x in (SELECT
Department,employee_id
FROM
Training
)
LOOP
— Print out a portion of a row,
— separated by commas and ended by a CR
htp.prn( x.department ||’,’|| x.employee_id);
END LOOP;
— Send an error code so that the
— rest of the HTML does not render
htmldb_application.g_unrecoverable_error := true;
END;
Step2: Create new button and dynamic action for on click behavior.
Action: Execute Javascript code
Paste the following code in the edit section:
window.open(‘f?p=&APP_ID.:0:&SESSION.:APPLICATION_PROCESS=down_txt:NO’, ‘_self’);
Conclusion:
In summary, the JET chart API provides a flexible way to enhance the functionality of charts in Oracle APEX, allowing for customizations such as adding markers, series properties, highlighting patterns etc.
In summary, using PL/SQL inbuilt packages we can generate the text file using the above approach which also provides the functionality to reuse globally.