in

Oracle Apex: Download CSV from Interactive Report from Another Page

This Oracle Apex tutorial shows, how to download a CSV file from the interactive report by calling it from another page with parameters. It will directly download the CSV file without opening that page having the interactive report.

To demonstrate this example, I am using the following EMPLOYEES table:

CREATE TABLE  "EMPLOYEES" 
   (  "EMPLOYEE_ID" NUMBER(6,0), 
   "FIRST_NAME" VARCHAR2(20), 
   "LAST_NAME" VARCHAR2(25), 
   "EMAIL" VARCHAR2(25), 
   "PHONE_NUMBER" VARCHAR2(20), 
   "HIRE_DATE" DATE, 
   "JOB_ID" VARCHAR2(10), 
   "SALARY" NUMBER(8,2), 
   "COMMISSION_PCT" NUMBER(2,2), 
   "MANAGER_ID" NUMBER(6,0), 
   "DEPARTMENT_ID" NUMBER(4,0)
   )
/

You can create this table in your schema and insert some data to practice this example.

1. Create a Page in Oracle Apex for the Interactive Report

I have created a page number 10 and created an Interactive Report in it with a Page Item P10_EMPID.

Used the following SQL query and the settings for the interactive report:

select EMPLOYEE_ID,
       FIRST_NAME,
       LAST_NAME,
       EMAIL,
       PHONE_NUMBER,
       HIRE_DATE,
       JOB_ID,
       SALARY,
       COMMISSION_PCT,
       MANAGER_ID,
       DEPARTMENT_ID
  from EMPLOYEES
 where employee_id = :P10_EMPID

Page Items to Submit: P10_EMPID

Below is the screenshot of the above settings:

Oracle Apex Interactive Report with Page Item

2. Set the Attributes of the report as shown in the below image

Oracle Apex Interactive Report Attributes

Save the changes for Page 10. Now we will call this report from another page with that page's Employee ID as a parameter to Page 10.

3. Create a Button on Another Page to Download CSV file

I have a Page 3 in my application having the item P3_EMPLOYEE_ID.

I created a button "Download CSV" with target action to "Redirect to URL" and added the following URL in it:

f?p=&APP_ID.:10:&SESSION.:CSV:NO:RP:P10_EMPID:&P3_EMPLOYEE_ID.

You can notice in the above URL, that I am passing the page item P3_EMPLOYEE_ID as a parameter to page 10 item P10_EMPID. Also, you can change the CSV to other formats such as PDF, XLS, RTF, etc.

Below is the screenshot:

Oracle Apex button for custom URL.

Save the changes for the page and run the page to test.

Now when you will click on the Button Download CSV it will directly download the CSV for the employee id stored in page item P3_EMPLOYEE_ID.

Below is the sample of CSV content:

"Employee Id","First Name","Last Name","Email","Hire Date","Job Id","Salary","Commission Pct","Manager Id","Department Id","Phone Number"
"103","Alexander","Hunold","AHUNOLD","03-JAN-06","IT_PROG","9000","","102","60","590.423.4567"

See also:

Written by Vinish Kapoor

An Oracle Apex Consultant, Oracle ACE, and founder of foxinfotech.org and orclqa.com a question and answer forum for developers.

guest

7 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments