Here are steps I used to archive my goal:
- start command line (CMD)
-
set NLS_LANG variable
set NLS_LANG=.UTF8
-
start sqlplus and log to database
sqlplus user/pwd@db
-
set long line size and avoid paging
SQL> set linesize 4000
SQL> set pagesize 0 -
set markup html in sqlplus
SQL> set markup html on spool on
It is important to use spool on clause, as it adds html header to spool file when spooling is started -
start spooling
SQL> spool a.html
-
run your query
-
turn off spooling
SQL> spool off
- open file in Excel
Cheers, Paweł
11 comments:
one thing you can try as well:
define a dsn for ODBC in the client to the Oracle data provider and your database alias, setup oracle client on that pc and then run the query directly from inside Excel, using a SQL statement from inside the spreadsheet.
works quite well.
ODBC is also an solution. But in my case I could not force it to work correctly with UTF8 data. I had data in many languages and lot of data get corrupted that way.
Pawel,
This trick is great as I have an web application which handles many languages and I could not get output which is readable from queries. Thanks for the good tip.
- Susanta
Pawel,
It is really working well. But is there any way we can remove this initial sql statement and add column headings to excel?
Your help is really appreciated.
How to add a column header to this html output?
Can you create and HTML with mutiple worksheet with this method, if so how???
Now how do you add another sheet ?
Regards,
Sanjay
Hi Sanjay and Anonymous,
This is not possible to add another sheet with this method. This is just to dump data fast to excel.
To have fully featured XML, that is readable by Excel try this:
1. Save small excel file as .xml file
2. analyze .xml that you get. It will contain tags like Table, Row, Cell, Data, and what you are interested in "ss:Worksheet"
But to get this done this way, SQL*Plus is not enough. You will have to do some more codding...
BR/Paweł
Hello.
First of all, this a nice and simple solution. I'm using it every day.
Rao.
You can add the heading removing obviating the command "set pagesize 0"
Also, you can edit the file from the console to remove all the extra information you don't want.
Thanks.
Alex.
Sorry...there was a small mistake on my previous message.
IF you remove pagesize statement, you will have your headings every 10 records. Since we want to have a heading just on the first line, i recommend you to a value grater than the records returned in case you know that value, or to a high value like 99999999.
Thanks.
Alex.
See some examples here.. http://shonythomas.blogspot.in/2011/07/export-and-create-excel-file-from.html
Post a Comment