duminică, 27 martie 2016

SQL Plus query result in xls file

If you need to obtain the result of a query in an Excel file, follow these example:

1. Create an sql file called 'MyScript.sql' (just as example) that will contain somehting like this:
alter session set current_schema = test;

set markup html on
set feedback off
set pagesize 0 embedded on
spool C:\report.xls

select
    'Header1',
    'Header2',
    'Header3'
from dual
union all
select
   <column1>,
   <column2>,
   <column3>
from <table>;

spool off
set markup html off

2. Use SQL Plus to run this .sql file
  a. From cmd type 'sqlplus <schema>/<password>@<server_name>' (find <server_name> in tnsnames.ora file)
  b. Type ' @<full_path_to_your_sql_file>'
3. You will find the generated file in C:\report.xls

Niciun comentariu:

Trimiteți un comentariu