Seamless Export in Oracle APEX: Export a Region data with a Single Click (No Page Submission!)

Farhan AkramFarhan Akram
3 min read

In modern web applications, user experience matters. No one likes to lose their place or wait for full page reloads just to download a report. If you're building with Oracle APEX and want to offer users the ability to export a report with one click โ€” without submitting the page โ€” you're in the right place.

This article shows you how to export a region (like an Interactive Report or Interactive Grid) using a JavaScript-based trigger that keeps your page state intact.

๐Ÿงญ What You'll Build

A custom solution that:

  • Generates a file via a PL/SQL process

  • Shows a toast message while downloading

  • Triggers file download in the background

  • Works with a single click, no page reload!


๐Ÿ› ๏ธ Step-by-Step Guide


โœ… Step 1: Create an AJAX Process to Generate the File

In APEX Page Designer:

  • Go to Processing โ†’ Right-click โ†’ Create โ†’ Ajax Callback

  • Name it: GET_FILE

  • Code example (generating Excel data):

DECLARE
  l_blob        BLOB;
  l_mime_type   VARCHAR2(255);
  l_filename    VARCHAR2(255);
BEGIN
  SELECT BLOB001 BLOB_CONTENT, C002 MIME_TYPE,C001 FILENAME
  INTO l_blob, l_mime_type, l_filename
  FROM apex_collections
  WHERE collection_name = 'FILE';

  -- set the headers
  OWA_UTIL.MIME_HEADER(l_mime_type, FALSE);
  HTP.P('Content-length: ' || DBMS_LOB.GETLENGTH(l_blob));
  HTP.P('Content-Disposition: attachment; filename="' || l_filename || '"');
  OWA_UTIL.HTTP_HEADER_CLOSE;

  -- download the blob
  WPG_DOCLOAD.DOWNLOAD_FILE(l_blob);

  APEX_APPLICATION.STOP_APEX_ENGINE;
END;

โœ… Step 2: Create a JavaScript Function to Show Toast Message

Go to Page > Function and Global Variable Declaration and add:

function showToast(msg) {
    window.toast = $(`
    <div class="t-Alert t-Alert--info t-Alert--defaultIcons t-Alert--horizontal"
         style="
           position: fixed;
           top: 60px;
           right: 20px;
           z-index: 9999;
           min-width: 300px;
           background-color: #1976D2;
           color: white;
           box-shadow: 0 2px 6px rgba(0,0,0,0.2);
           border-radius: 8px;
         ">
      <div class="t-Alert-wrap" style="display: flex; align-items: center;">
        <div class="t-Alert-icon" style="padding: 10px; background-color: unset;color:white">
          <span class="fa fa-download" style="font-size: 20px;"></span>
        </div>
        <div class="t-Alert-content" style="padding: 10px; flex: 1;">
          <div class="t-Alert-body" style="font-size: 14px;">${msg}</div>
        </div>
      </div>
    </div>
  `);
    toast.appendTo('body')
        .delay(3000);
}

โœ… Step 3: Create a Download Button

  • Label: Download

  • Button Action: Defined by Dynamic Action


โœ… Step 4: Create a Dynamic Action on the Button

๐Ÿ”น Event: Click

๐Ÿ”น Selection Type: Button

โ–ถ๏ธ True Action 1: Execute JavaScript (Show Toast)

showToast('File is being download!');

โ–ถ๏ธ True Action 2: Execute Server-side Code (AJAX)

  • Action: Execute PL/SQL Code

  • PL/SQL Code:

DECLARE
    l_export       apex_data_export.t_export;
    l_region_id    number;
BEGIN
APEX_COLLECTION.CREATE_OR_TRUNCATE_COLLECTION('FILE');
   SELECT region_id into l_region_id
     FROM apex_application_page_regions
    WHERE application_id = :APP_ID
      and page_id = :APP_PAGE_ID
      and static_id = 'projects_report';-- Static ID of region

    l_export := apex_region.export_data (
         p_format       => apex_data_export.c_format_xlsx,
         p_page_id      => :APP_PAGE_ID,
         p_region_id    => l_region_id );

    APEX_COLLECTION.ADD_MEMBER (
        p_collection_name => 'FILE',
        p_c001 => l_export.FILE_NAME,
        p_c002 => l_export.MIME_TYPE,
        p_blob001 => l_export.content_blob);
END;

โ–ถ๏ธ True Action 3: Execute JavaScript Code (Download the File)

window.toast.fadeOut(400, function () {
         $(this).remove();
       });
var link = $('<a>')
    .attr('href', 'f?p=&APP_ID.:&APP_PAGE_ID.:&SESSION.:APPLICATION_PROCESS=GET_FILE::::')
    .appendTo('body');
link[0].click();
link.remove();

๐Ÿงช Result

With just a click:

  • User sees a success toast

  • PL/SQL prepares the file

  • File is auto-downloaded

  • No page reload ๐ŸŽ‰


๐Ÿ“ Conclusion

This method gives you complete control over how files are generated and delivered in Oracle APEX. Whether it's Excel, PDF, or CSV โ€” you can offer instant downloads using AJAX, toasts, and JavaScript, without disrupting the user's flow.

1
Subscribe to my newsletter

Read articles from Farhan Akram directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Farhan Akram
Farhan Akram

๐Ÿ‘‹ Hi, I'm Muhammad Farhan Akram โ€” an Oracle APEX developer and system architect with 13+ years of experience building scalable, low-code solutions. ๐Ÿ”ง I specialize in: Oracle APEX, PL/SQL, Oracle Forms & Reports Data modeling, performance tuning, REST APIs APEX plugin development, JavaScript, and UI customization ๐Ÿ’ผ I've led projects in healthcare, oil & gas, finance, and shipping โ€” including Oracle Forms-to-APEX migrations and full-stack enterprise systems.