Oracle APEX - 使用按钮将查询导出为CSV

时间:2018-05-16 15:23:24

标签: oracle oracle-apex

我在顶点页面上有一个按钮,允许用户将数据(基于最终用户看不到的查询)导出到CSV文件中。

如何将此按钮链接到我的查询,以便我们可以将结果导出为CSV文件?

由于

2 个答案:

答案 0 :(得分:5)

我通过使用condition = never定义页面上的区域来完成此操作,但您仍然可以使用相关的URL调用下载,您可以从"下载为CSV"使用浏览器的“检查元素”功能在区域 时链接。

enter image description here

您将看到请求是带有前缀的区域ID。 所以你可以使用这个调用下载

/ords/f?p=your_app:your_page:your_session:FLOW_EXCEL_OUTPUT_R571755827567965848_en

或让您的按钮调用相同的JavaScript

window.location.href=apex.server.url({p_request: 'FLOW_EXCEL_OUTPUT_R571755827567965848_en'},2);

即使区域条件为从不,这也会有效。

答案 1 :(得分:1)

感谢Scott Spendolini,我使用他的链接:https://spendolini.blogspot.fr/2006/04/custom-export-to-csv.html

我只是用我的查询创建一个报告区域。添加一个按钮,可以转到我创建的空白页面。在那个页面上,我添加了一个PL / SQL进程,它将触发" On Load - Before Header "在该过程的源代码中,我使用此代码:

begin
-- Set the MIME type
owa_util.mime_header( 'application/octet', FALSE );
-- Set the name of the file
htp.p('Content-Disposition: attachment; filename="emp.csv"');
-- Close the HTTP Header
owa_util.http_header_close;
-- Loop through all rows in EMP
for x in (select e.ename, e.empno, d.dname
from emp e, dept d where e.deptno = d.deptno
  and e.deptno like :P1_DEPTNO)
loop
 -- Print out a portion of a row,
 -- separated by commas and ended by a CR
 htp.prn(x.ename ||','|| x.empno ||','||
         x.dname || chr(13));
end loop;
-- Send an error code so that the
-- rest of the HTML does not render
htmldb_application.g_unrecoverable_error := true;
end;