Oracle APEX download csv example
Updated
•1 min readD
I ❤️ Oracle APEX
declare
l_csv clob;
l_line varchar2(4000);
begin
-- Add headers (Replace with your actual column names)
l_line := '"COLUMN1","COLUMN2"';
l_csv := l_line || chr(10);
-- Loop through data (Replace with your table or query)
for rec in (
select COLUMN1, COLUMN2
from dual
)
loop
l_line := '"' || rec.column1 || '","' || rec.column2 || '"';
l_csv := l_csv || l_line || chr(10);
end loop;
-- Download CSV
owa_util.mime_header ('text/csv', false);
htp.p (
'Content-Disposition: attachment; filename="download.csv"'
);
owa_util.http_header_close;
htp.p (l_csv);
apex_application.stop_apex_engine; -- Important to stop rendering
end;