user524230
user524230

Reputation: 91

Create an Excel Spreadsheet from a Oracle Database

I have a table in a Oracle database. I have to create a complex spreadsheet structure from the Oracle table. I am looking for best approach to achieve this. Can I use SSIS or use some Oracle utilities to create the spreadsheet.

Any help would be extremely appreciated.

Thanks in advance.

Regards Dibs

Upvotes: 4

Views: 31652

Answers (5)

Aditya Patel
Aditya Patel

Reputation: 1

set linesize 4000 pagesize 0 colsep ',' set heading off trimspool on trimout on

spool c:/file.xls

select * from tableName;

spool off;

this will generate your file.xls in c drive. You can give any address and if you want column heading then remove "heading off" clause and set pagesize to some numeric value.

Upvotes: 0

APC
APC

Reputation: 146219

I suppose the problem is, just how complex is your "complex structure"?

Programming IDEs such as Oracle SQL Developer or Quest TOAD have wizards to export data table to CSV files.

If you want to join data from multiple tables you could use a view, or even write a SQL statement

select e.ename||','||d.dname
from   emp e
       join dept d on ( e.deptno = d.deptno )
/

(rembering that columns can often contain data which includes commas, so you may want to use a more unusual character - or set of characters - as your separator.)

Another quick way of doing soemthing is to use SQL*Plus's HTML reporting function. Many spreadsheet tools can import well-structured HTML and XML without a snatch. Find out more.

If you want to flatten a hierarchical structure or something even more convoluted you'll probably need to move into PL/SQL. A hand-rolled approach would use a variant of the above statement fitted to use UTL_FILE:

declare
    csv_fh  utl_file.filetype;
begin
    csv_fh := utl_file.fopen('C:\temp', 'data_export.csv', 'W');
    for r in   (  select e.ename, d.dname
                  from   emp e
                  join dept d on ( e.deptno = d.deptno )
                ) loop
        utl_file.put_line(csv_fh, r.ename||'|'||r.dname;
    end loop;
    utl_file.fclose(csv_fh);
end;

If you want to export specifically to Excel (i.e. a .XLS file) then you'll need to go beyond Oracle built-ins. The usual solution for exporting straight from PL/SQL to Excel is Tom Kyte's OWA_SYLK wrapper for the SYLK api. Find out more.

This works with single worksheets. If you want to export to multiple worksheets there are a couple of alternative solutions.

Sanjeev Sapre has his get_xl_xml package. As the name suggests it uses XML to undertake the transformation. Find out more.

Jason Bennett has written a PL/SQL object which generates an Excel XML document. Find out more.

Upvotes: 7

ora_excel
ora_excel

Reputation: 112

You can use ORA_EXCEL package to create Excel documents with complex structure. ORA_EXCEL have basic but powerful components which you may use to build complex Excel files.

Check functions list at: http://www.oraexcel.com/documentation

Upvotes: 3

Cos Callis
Cos Callis

Reputation: 5084

There is a 'disconnected' version of SSRS report descriptions called .RDLC (Report Definition Language Client). This is a subset of the RDL that is part of SSRS. There are report viewer controls that have built in exporters for Excel and PDF formats. The viewer control is available for both windows forms and web forms. The datasource for these reports are generic DataSets or data objects that are agnostic to data sources (SQL, Oracle,...smoke signals..)

http://www.highoncoding.com/Articles/339_Creating_Charts_Using_Aspnet_ReportViewer_Control.aspx

http://msdn.microsoft.com/en-us/library/ms251771%28VS.80%29.aspx

Upvotes: 0

Hank Gay
Hank Gay

Reputation: 71939

The first thing I would try is just dumping the values I wanted to CSV. Excel should be able to import that just fine, and it's often easier to fiddle with Excel formulas, etc., manually than to try to automate it. If you're using Oracle SQLDeveloper, there's an option to export results to CSV. If you're using SQL*Plus, then you can use set colsep , to make Oracle use commas to separate the columns. You'll probably want to do some more formatting tweaks if you're using SQL*Plus, though.

Upvotes: 0

Related Questions