How to generate SQL results to Excel sheet (Oracle) - sql

I am using SQL developer. I need to export the SQL result set to Excel sheet. I know how to export it by manually.
Currently I am using a batch file. Which in turn run's multiple SQL script files. At the end there is a 1 SQL script which contains multiple SQL select statements. Now I need to export these result to excel sheet while running batch file itself.
Batch file Name: Mytest.SQL it contain multiple script files as below.
##test1.sql;
##test2.sql;
##test3.sql;
##test4.sql;
The last script test4.sql contains multiple select statements, which needs to be exported into multiple excels. Please suggest any solution.

Months ago I have found this solution. A ready to use package to unload query result into xlsx file, also with formating. Here is the link. There is also a description how to use the package.
pl/sql package to unload as xlsx
Hope this helps.

I used to do this VB-script, ie I run queries from Excel:
Set OraSession = CreateObject("OracleInProcServer.XOraSession")
Set ThisWorkbook.OraDatabase = OraSession.OpenDatabase(sDB$, sUSERID$, 0&)
Set OraDynaSet = ThisWorkbook.OraDatabase.CreateDynaset(QueryText, 0&)
You can in this macro calls a script and write cycle data in Excel

Do you need a specific xls file or a csv file?
If you want a csv you can spool a file with sql.
For xls files, you can't do it easily, you'll probably have to go through another programming langage like java or c# or whatever with a specific library to build your report (e.g. for Java Apache POI).

Related

oracle sql (toad) - executing multiple queries, save to individual excel files

There are 8 separate queries I need to run and save to individual excel files. What's the best way of running this in toad rather than executing/saving each query?
Just figured out how to do this and I'm posting so that anyone else with the same problem can look at this as a possible solution.
Use the Automation Designer feature in TOAD for Oracle. Select export dataset and write in your query that you want exported and into what format you want it exported (I chose excel file). Repeat this process for all your queries. Select all "actions" and run.

How to export powershell results in to one excel sheet in different pages

I am trying to export SQL server query results to excel using power shell. My query runs on all the servers in a domain. My powershell query need to load results of each server to each page in 1 Excel sheet. Please suggest
What I suggest you can do is get the results of the SQL query from each server in individual csv files (by using export-csv command) and then combine each result in one single sheet. This link will be helpful. Copy Excel Worksheet from one Workbook to another with Powershell. Although a bit lengthy but it will serve your purpose.

Automate multiple script files .sql and export result to excel SSIS

I'm trying to execute multiple SQL files and export the results to Excel files.
Until now, i used the «For each lood container» with the «Execute SQL task» and it's running well...
I think i should use «For each lood container» and «Data flow task», but i can't use multiple exports in it.
Thank you in advance for your help,
For multiple exports,
you can use a variable with expression for your excel file name. Increment it for each loop and use in your FileSystem Task to create the file.

creating batch file to run sql query in sql developer and store result in excel sheet

I am creating a batch file that will be executed daily at a specific time. The batch file will execute a .sql file. The .sql contains a complex select statement. I have created the sql file using Sql Developer. Also the output of the sql must be stored in an excel sheet with name as todays date.
I have read posts related to batch file to run the sql script but have not found clear answers. I am completely new to batch files.
Thanks
try to use bcp command http://sqlfool.com/2008/12/bcp-basics/ with queryout option

Export data to Excel file using SSIS

I have SSIS Package which Exports Data from table to Excel file
Control Flow :-
Data Flow :-
This is My Step :-
Drop Excel Table
Create Excel Table with format as of my Select Query which i used to retrieve data from database
Insert Data from Database to Excel file
I Used Query Like Select * From Table Where --Some Condition
I retrieve 3000 rows out of 10000 rows and put that 3000 rows in my excel sheet.
But when open my excel sheet i saw scrollbar which goes till 10000th row and ends hence my excel sheet size also increses . how can i reduce my excel sheet size ? my excel sheet contains only 3000 rows then why blank cells which goes till 10000th row ?
SQL Server 2008 &
Visual Studio 2008 with BIDS
I believe your issue is around the method in which you are using to create the file. You have two alternatives and both should fix your issue:
Solution #1:
You can create an Excel file with those predefined columns, essentially your empty output file - this would act as your 'Template File'. Your flow would then be this:
File System Task - Copy template file to output or working directory (rename if necessary)
OLEDB Source Task - Query your source for the data (3000)
Data Conversion Task
Excel Destination Task - Put data into new Excel file
Note: You already have steps 2 thru 3 complete, you just need to make sure you are connecting to the new Excel file. Also, to clarify, step 1 is outside the Control Flow Task.
This way is helpful because you always have a blank and consistently formatted Excel file to copy and work with.
Solution #2:
The other option is to use a Script Task and create the Excel file - you could also load the data into the file in this task. This requires some basic understanding of VB.NET or C#. Basically you would need to get a XLS library (like NPOI). This is more complicated, but gives you the best functionality.
I recommend you try solution #1 and see how that works for you.
Drop table SheetName doesn't delete the sheet instead it just deletes the row . If for the 1st time you have loaded 10K rows and then again executed the package by restricting the number of rows to 3K ,the excel file will still contain those 10K empty rows as it retains the sheet along with the empty spaces .
You can use script task to delete the sheet using COM obects .But for that you need to place the Excel PIA(Primary Interop Assemply) to make it visible for VSA or else create a new excel file every time the package runs
Else as suggested by Nicarus use File System Task to delete the existing file and create a new Excel file on every execution .
Diagram :
File System Task :
Use the same components and the query for Create Table using Execute SQL task and your DFT