If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > Oracle > Export SQL Plus calling a SQL Script to Excel

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-02-12, 16:51
ColoradoSunshine ColoradoSunshine is offline
Registered User
 
Join Date: Jul 2012
Posts: 2
Export SQL Plus calling a SQL Script to Excel

Hello All!

I am trying to export results from SQL Plus to Excel and using the following super simple code in my SQL Script:

set feedback off markup html on spool on
alter session set nls_date_format='YYYY-MM-DD';

set PAGESIZE 50000
set LINESIZE 10000

set termout off

spool myresults.xls

select fields from tablename;

spool off
set markup html off

The results are exported into an Excel worksheet, but when opening the file, receive the following error:
"The file you are trying to open, 'myresults.xls', is in a different format than specified by the file extension. Verify that the file is not corrupted and is from a trusted source before opening the file. Do you want to open the file now?"

If I click yes, the file opens fine. I save the file to a different location and it appears to be an .xls file, but since it is created using the "markup html on" set command in my SQL, I wonder if there is HTML in the doc?

Any help to be able to create the Excel file this easy way and be able to open it without an error message?

I do not have permissions to change my users' registry settings, etc.

Thanks!
Sunny
Reply With Quote
  #2 (permalink)  
Old 07-02-12, 19:21
anacedent anacedent is offline
Registered User
 
Join Date: Aug 2003
Location: Where the Surf Meets the Turf @Del Mar, CA
Posts: 7,095
>spool myresults.xls
simply naming the *xls does NOT make it an Excel file.
EXCEL using ODBC can connect directly to Oracle RDBMS & then issue SQL;
without any intermediate data file.

Search results for "excel" - Oracle FAQ
https://forums.oracle.com/forums/thr...174552#9360007
__________________
You can lead some folks to knowledge, but you can not make them think.
The average person thinks he's above average!
For most folks, they don't know, what they don't know.
Reply With Quote
  #3 (permalink)  
Old 07-02-12, 19:25
ColoradoSunshine ColoradoSunshine is offline
Registered User
 
Join Date: Jul 2012
Posts: 2
Thank you for your response.

The requirement is to create an Excel dump from Oracle. To use Excel to query Oracle is not an option in this situation.

So I am still on the hunt for a solution.
Reply With Quote
  #4 (permalink)  
Old 07-02-12, 19:30
anacedent anacedent is offline
Registered User
 
Join Date: Aug 2003
Location: Where the Surf Meets the Turf @Del Mar, CA
Posts: 7,095
>The requirement is to create an Excel dump from Oracle.
Oracle has no capability to write a pure Excel spreadsheet file; which in a binary format.
Oracle can write plain text files either as Comma Separated Value or XML file; which Excel can import.
It is up to you to ensure the file content is in a format that Excel accepts.
__________________
You can lead some folks to knowledge, but you can not make them think.
The average person thinks he's above average!
For most folks, they don't know, what they don't know.
Reply With Quote
  #5 (permalink)  
Old 07-05-12, 08:21
beilstwh beilstwh is offline
Lead Application Develope
 
Join Date: Jun 2004
Location: Liverpool, NY USA
Posts: 2,343
should have been

spool myresults.html

which excel will open with no problems.
__________________
Bill
You do not need a parachute to skydive. You only need a parachute to skydive twice.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On