Saving sql query result as excel file in different spreadsheets

Hi,
I have exported the output of sql into excel sheet as follow:
SET LINESIZE 80
SET PAGESIZE 0
SET FEEDBACK OFF
SET SPOOL ON
SET TERMOUT OFF
SPOOL current_employees.csv
SELECT '"ID","Sales Amount","Region Id","Sales Date"' FROM dual;
set colsep ,
SELECT * FROM sales;
SPOOL OFF
But my question is how can I export SQL output in multiple excel spredsheets?
Is there anything by which I can switch my spreadsheets through the above SQL script?
Regards,
Ashish

Hi,
I have exported the output of sql into excel sheet as follow:
SET LINESIZE 80
SET PAGESIZE 0
SET FEEDBACK OFF
SET SPOOL ON
SET TERMOUT OFF
SPOOL current_employees.csv
SELECT '"ID","Sales Amount","Region Id","Sales Date"' FROM dual;
set colsep ,
SELECT * FROM sales;
SPOOL OFF
But my question is how can I export SQL output in multiple excel spredsheets?
Is there anything by which I can switch my spreadsheets through the above SQL script?
Regards,
Ashish

Similar Messages

  • How to save query result in excel file

    Hi all,
    How to save query result in excel file from sql*plus tool.
    thank you

    Do you really need an Excel file (binary) or a simple CSV?
    If you just need a CSV then search for DUMP_CSV at http://asktom.oracle.com or at this forum
    If you need formatting and/or multiple worksheets then you can use free tools like
    https://xml-spreadsheet.samplecode.oracle.com/ or https://exceldocumenttype.samplecode.oracle.com/
    Regards
    Marcus

  • Procedure to write Oracle Query Result to Excel file?

    Hi All,
    I have a requirement to write a procedure which will write the result of a Query (select statement) to a Excel file.
    I use a third party tool to do so but it fails when the query fetches more than 65000 records!
    Can someone suggest me a procedure ( may be written in PL/SQL ) which can be used to achieve this task?
    If there is a procedure available readily, can you please share it with me?
    Thanks in advance
    Himanshu Dabir

    There is a ready procedure (actually PL/SQL blocks by Tom Kyte) available at
    http://www.quest-pipelines.com/newsletter-v5/0704_C.htm
    but it also suffers from Microsofts limitation of 65536 rows per sheet.

  • Select query results into excel file

    Hi,
    I want to put the results of a select query in an csv file(tab separated columns). I dont want to spool command for this . Is there any other method to do this.
    Thanks

    To get data from oracle to excel to use odbc driver to achive this.

  • Export result of ssas query result to excel file

    Hi All,
    I have browsed a SSAS cube. I want to export result of SSAS cube into excel file.
    Kindly give your input.
    Thanks,
    Vivek singh

    Hi,
    I do not know whether there is a direct solution but there is an indirect way of doing it. I always follow this method if I ever want to get MDX results into Excel.
    1 - Install the DAX Studio (I know you want MDX results, so do not get confused by looking at the word DAX. Continue reading). You can download it from the following location.
    http://www.sqlbi.com/tools/dax-studio/
    2 - Once you install DAX Studio, Go to the Add-Ins ribbon. Click on DAX Studio. 
    3 - There is an option "Tabular Server" and there is a drop-down list where you can enter the SSAS (MD CUBE Server) server name. Enter the server name manually. If you have multiple SSAS Databases and if you are interested in a specific SSAS database
    enter "Initial Catalog=Your SSAS Database Name" in Additional Options section and Click Connect. You can successfully connect to the SSAS Server now.
    Here are the details described so far in pictorial representation.
    4 - Enter your MDX manually and execute the code via DAX studio and you will get your results right-away in Excel.
    Now, isn't that an elegant way of getting MDX results into Excel :) ? Besides Excel's Pivot Table option, I do not know whether there are any alternate solutions to this but wait for other Pros' comments as well.
     Best regards...
    Chandima Lakmal Fonseka

  • Saving jsp query results to csv file

    I have a query form jsp application which does as you would expect - throw in some search parameters - results set is returned - my question is how I go about writing an instance to save these results into a csv notepad file. I've used JBuilder a lot and within that it is relatively simple to create a save-to-file instance - is it the same within JDeveloper?? Sorry if this is a fairly obvious question - I just havent come across anything in the docs yet

    Try this in a JSP:
    <%
    response.setContentType( "text/x-csv" );
    response.setHeader( "Content-disposition", "inline;filename=myfilename.csv" );
    %>
    "value1","value2","value3"
    "valueX","valueY","valueZ"

  • Saving query results as excel

    hi,
    Is there a way to save the query results as excel programatically (some kind of utility which does the job)? we are using oracle 10g. This will be a nightly job.. so that every other day morning we have the huge excel report ready for viewing. Any help is appreciated..

    Did you think to try searching the forum? I typed in the EXACT string you used for your thread title and the first hit was ...
    Saving sql query result as excel file

  • Steps to save a Query/Report as Excel file in Share folder

    Hi,
    I have a requirement where i need to schedule a BI report automatically on a daily basis and save it in a Sharepoint folder as a excel file.  I have gone through the Forums but didnt get a clear idea on how to proceed this with.  I read about RSCRM_BAPI transaction but i hope we need to do this manually to save the file each time.  Also, in Broadcaster there are options only to send Email & save in Portal. 
    So, if anybody have idea on saving a Query/Report as excel file in a Share folder automatically, kindly help me in suggesting the steps to do this activity.
    Regards,
    Murali

    Hi
    1. Create Three Floders in AL11 i.e. in Apllication Server. Eg Name it F1, F2 and F3.
    2. First dump the .csv files into F1. (Name xyz.csv).
    3. Then using UNIX/WINDOWS (depends on your OS) script , first check the file is there are not in F1, if yes then rename the file with date and time or date and transfer the files from F1 to F2 i.e xyz06032010.csv.
    4. Then Create a small ABAP program to check the file in F2, if it is there then Trigger the Event, and using that event you execute teh PC.
    5. Then using UNIX/WINDOWS (depends on your OS) script , transfer the files from F2 to F3 i.e xyz06032010.csv
    6. Next day morning F1 and F2 are empty and F3 is having the backup files.
    So use this method, I used the similar logic and it is working fine.
    Timinings are importent i.e what time you need to dump the fule in F1 and what time you need to run UNIX/WINDOWS (depends on your OS) script , transfer the files from F1 to F2 and what time UNIX/WINDOWS (depends on your OS) script , transfer the files from F2 to F3.
    OR
    1. Create Two Floders in AL11 i.e. in Apllication Server. Eg Name it F1 and F2
    2. First dump the .csv files into F1. (Name xyz.csv)
    3. Then load the data using InfoPackage, through PC.
    4. At the end of the load Attach a simple Program to Move the xyz.csv file from F1 to F2.
    5. So next day the file will come to F1 and the it will load and at the end it will move to F2.
    Else  you can use simple one or two lines of UNIX/WINDOWS (depends on your OS) script to move the file from F1 to F2 , once you load is over.
    While moving the file from F1 to F2 you can append the date at the end of the file and then move to F2, it is use full for future reference.
    See Blogs and Article, similar logic...
    https://wiki.sdn.sap.com/wiki/display/profile/Surendra+Reddy
    How to transfer the Data from SAP-System to Non-SAP system without additional Cost/License
    /people/surendrakumarreddy.koduru/blog/2009/03/11/how-to-transfer-the-data-from-sap-system-to-non-sap-system-without-additional-costlicense
    To Check the Files/Reports in Application Server and Trigger Mail Alerts.
    http://www.sdn.sap.com/irj/scn/index?rid=/library/uuid/4096bf2d-bcea-2b10-4ab4-e0683830d9b2&overridelayout=true
    Thanks
    Reddy
    Edited by: Surendra Reddy on Mar 12, 2010 6:41 AM

  • Saving query result to a file

    Hi,
    I have a sql*developer version 1.5 but i am getting a problem while saving query result to a file. When i click on "script output "-> "file icon" nothing is showing.
    Can anyboby guide me whether its a bug or some other settings are required.
    I have oracle 10.2.0.3 working on linux.
    Thanks & regards
    Girish

    I am getting the same thing and as far as I know it is a bug.
    As a workaround, you can either copy the contents of the script output or run the query as a statement (F9) instead of as a script (F5) and export the query results from the results tab.

  • Saving query results to text file

    Hi experts,
    I would like to save a query results to text file.
    The query has desined to the correct structure and I wish the query results will be saved automaticly to text file every time the query is running.
    The query should cintain some sql code that will save the query to text file instead of show the query results.
    What function of SQL should I add to query to achieve that goal. (The query is a long one).
    Thanks in advance,
    Joseph

    If you are talking about Query Manager, it is not difficult to do.  No matter how long your query coding is, just go to the start point of your query.  Then press CtrlShiftEnd to select all the TEXTs.  CtrlC and CtrlV will copy the text (query codes) to text file easily.
    Thanks,
    Gordon

  • How to save query result on the file server as excel file?

    Hi everyone,
    I need to save the the query result on the file server as excel file.
    Do you have any idees how can I do it?
    Regards
    Erwin

    i dont think you can save as excel file but you can save it as CSV use APD or RSCRM BAPI for this

  • SQL Query results to CSV as two worksheets

    I'm trying to take two SQL queries and get the results sent to a CSV file on two worksheets.  Looking online I have not found a solid example of using the Excel ComObject to create a CSV then add a new worksheet to the CSV file.  An added bonus
    would be using AutoFit on the columns so everything is easily visible.
    Code found online got me the following script which does work, however it takes 12 minutes to pipe the SQL queries to Excel.  Switching to a CSV and the script executes in 5 seconds.
    This is another nice to have, I was also looking the best way to look at the results (only 1 column) and depending on the length of the data, insert what Excel would call a Cell thereby shifting cells RIGHT but so far have found no clear examples of how
    to accomplish that.  My guess would be modifying my SQL queries but I've posted a question on StackOverFlow and someone suggested modifying the PowerShell Table created from the SQL dataset.Tables
    Code:
    $docs = "C:\Scripts\Output.xlsx"
    If (Test-Path $docs){Remove-Item $docs}
    Function Run-Query {
    param([string[]]$queries,[string[]]$sheetnames)
    ## - Create an Excel Application instance:
    $xlsObj = New-Object -ComObject Excel.Application
    $xlsObj.DisplayAlerts = $false
    $xlsWb = $xlsobj.Workbooks.Add(1)
    ## - Create new Workbook and Sheet (Visible = 1 / 0 not visible)
    $xlsObj.Visible = 0
    $time = 2
    for ($i = 0; $i -lt $queries.Count; $i++){
    $percentage = $i / $time
    $remaining = New-TimeSpan -Seconds ($time - $i)
    $message = "{0:p0} complete" -f $percentage, $remaining
    Write-Progress -Activity "Creating Daily Reboot Spreadsheet" -status $message -PercentComplete ($percentage * 100)
    $query = $queries[$i]
    $sheetname = $sheetnames[$i]
    $xlsSh = $xlsWb.Worksheets.Add([System.Reflection.Missing]::Value, $xlsWb.Worksheets.Item($xlsWb.Worksheets.Count))
    $xlsSh.Name = $sheetname
    ### SQL query results sent to Excel
    $SQLServer = 'ServerName'
    $Database = 'DataBase'
    ## - Connect to SQL Server using non-SMO class 'System.Data':
    $SqlConnection = New-Object System.Data.SqlClient.SqlConnection
    $SqlConnection.ConnectionString = "Server = $SQLServer; Database = $Database; Integrated Security = True"
    $SqlCmd = New-Object System.Data.SqlClient.SqlCommand
    $SqlCmd.CommandText = $query
    $SqlCmd.Connection = $SqlConnection
    ## - Extract and build the SQL data object '$Table2':
    $SqlAdapter = New-Object System.Data.SqlClient.SqlDataAdapter
    $SqlAdapter.SelectCommand = $SqlCmd
    $DataSet = New-Object System.Data.DataSet
    $SqlAdapter.Fill($DataSet)
    $SqlConnection.Close()
    $Table1 = $DataSet.Tables["Table"]
    ## - Build the Excel column heading:
    [Array] $getColumnNames = $Table1.Columns | SELECT ColumnName
    ## - Build column header:
    [Int] $RowHeader = 1
    foreach ($ColH in $getColumnNames)
    $xlsSh.Cells.item(1, $RowHeader).font.bold = $true
    $xlsSh.Cells.item(1, $RowHeader) = $ColH.ColumnName
    $RowHeader++
    ## - Adding the data start in row 2 column 1:
    [Int] $rowData = 2
    [Int] $colData = 1
    foreach ($rec in $Table1.Rows)
    foreach ($Coln in $getColumnNames)
    ## - Next line convert cell to be text only:
    $xlsSh.Cells.NumberFormat = "@"
    ## - Populating columns:
    $xlsSh.Cells.Item($rowData, $colData) = $rec.$($Coln.ColumnName).ToString()
    $ColData++
    $rowData++; $ColData = 1
    ## - Adjusting columns in the Excel sheet:
    $xlsRng = $xlsSH.usedRange
    [void] $xlsRng.EntireColumn.AutoFit()
    }#End For loop.
    #Delete unwanted Sheet1.
    $xlsWb.Sheets.Item('Sheet1').Delete()
    #Set Monday to Active Sheet upon opening Workbook.
    $xlsWb.Sheets.Item('Cert').Activate()
    ## ---------- Saving file and Terminating Excel Application ---------- ##
    $xlsFile = "C:\Scripts\Output.xlsx"
    [void] $xlsObj.ActiveWorkbook.SaveAs($xlsFile)
    $xlsObj.Quit()
    ## - End of Script - ##
    start-sleep 2
    While ([System.Runtime.Interopservices.Marshal]::ReleaseComObject($xlsRng)) {'cleanup xlsRng'}
    While ([System.Runtime.Interopservices.Marshal]::ReleaseComObject($xlsSh)) {'cleanup xlsSh'}
    While ([System.Runtime.Interopservices.Marshal]::ReleaseComObject($xlsWb)) {'cleanup xlsWb'}
    While ([System.Runtime.Interopservices.Marshal]::ReleaseComObject($xlsObj)) {'cleanup xlsObj'}
    [gc]::collect() | Out-Null
    [gc]::WaitForPendingFinalizers() | Out-Null
    }#End Function
    $queries = @()
    $queries += "Query1"
    $queries += "Query2"
    $sheetnames = @('Cert','Prod')
    Run-Query -queries $queries -sheetnames $sheetnames

    Here's what I ended up with that accomplishes my goal.  I learned it's not possible to create a CSV with two worksheets since Excel will allow this but the CSV cannot be saved with the second worksheet.  Instead, I create two CSV files then merge
    them into one Excel workbook, one CSV per worksheet.  In my case, this happens in 5 seconds.  There is one thing which must be mentioned, I've seen this script fail the first time it is run but will successfully run the second time.
    Also note, after much trial and error, this code correctly cleans up the Excel ComObject!!  -Thanks go to JRV.
    $docs = "D:\Scripts\MonthlyReboots.xlsx"
    IF (Test-Path $docs){Remove-Item $docs}
    $csv1 = "D:\Scripts\Cert.csv"
    IF (Test-Path $csv1){Remove-Item $csv1}
    $csv2 = "D:\Scripts\Prod.csv"
    IF (Test-Path $csv2){Remove-Item $csv2}
    Function Run-Query {
    param([string[]]$queries,[string[]]$sheetnames,[string[]]$filenames)
    Begin{
    $SQLServer = 'ServerName'
    $Database = 'DataBase'
    $SqlConnection = New-Object System.Data.SqlClient.SqlConnection
    $SqlConnection.ConnectionString = "Server = $SQLServer; Database = $Database; Integrated Security = True"
    $Excel = New-Object -ComObject Excel.Application
    $Excel.Visible = 0
    $dest = $Excel.Workbooks.Add(1)
    }#End Begin
    Process{
    For($i = 0; $i -lt $queries.Count; $i++){
    $SqlCmd = New-Object System.Data.SqlClient.SqlCommand
    $SqlCmd.CommandText = $queries[$i]
    $SqlCmd.Connection = $SqlConnection
    $SqlAdapter = New-Object System.Data.SqlClient.SqlDataAdapter
    $SqlAdapter.SelectCommand = $SqlCmd
    $DataSet = New-Object System.Data.DataSet
    $SqlAdapter.Fill($DataSet)
    $DataSet.Tables[0] | Export-Csv -NoTypeInformation -Path "D:\Scripts\$($sheetnames[$i]).csv" -Force
    }#end for loop.
    }#End Process
    End{
    $SqlConnection.Close()
    #Excel magic test!
    For($i = 0; $i -lt $queries.Count; $i++){
    $loopy = (Resolve-Path -Path $filenames[$i]).ProviderPath
    $Book = $Excel.Workbooks.Open($loopy)
    $next = $Excel.workbooks.Open($loopy)
    $next.ActiveSheet.Move($dest.ActiveSheet)
    $xlsRng = $dest.ActiveSheet.UsedRange
    $xlsRng.EntireColumn.AutoFit() | Out-Null
    $dest.sheets.item('Sheet1').Delete()
    $xlsFile = "D:\Scripts\MonthlyReboots.xlsx"
    [void] $Excel.ActiveWorkbook.SaveAs($xlsFile)
    $Excel.Quit()
    While ([System.Runtime.Interopservices.Marshal]::ReleaseComObject($xlsRng)) {'cleanup xlsRng'}
    While ([System.Runtime.Interopservices.Marshal]::ReleaseComObject($next)) {'cleanup xlsSh'}
    While ([System.Runtime.Interopservices.Marshal]::ReleaseComObject($Book)) {'cleanup xlsWb'}
    While ([System.Runtime.Interopservices.Marshal]::ReleaseComObject($Excel)) {'cleanup xlsObj'}
    [gc]::collect() | Out-Null
    [gc]::WaitForPendingFinalizers() | Out-Null
    }#End end block.
    }#End function run-query.
    $queries = @()
    $queries += @'
    Select * from table1
    $queries += @'
    Select * from table2
    $sheetnames = @("Cert","Prod")
    $filenames = @("D:\Scripts\Prod.csv","D:\Scripts\Cert.csv")
    Run-Query -queries $queries -sheetnames $sheetnames -filenames $filenames
    Start-Sleep -Milliseconds 50
    Invoke-Item D:\Scripts\MonthlyReboots.xlsx

  • Require Code which export SQL Query resuluts to excel using checkbox option

    Hi All,
    I need a sample code which can export the SQL Query results directly to an excel file using checkbox option. for example
    if I select checkbox1 and press a save button, then on backend SQL Query will execute and save the results in a excel file and so on.
    Thanks in advance..
    Regards,
    Chetan

    Thanks for the Code.
    Actually I need a code which is based on combo base values and when I click on Button, the SQL Query will execute using SQL Connection string and the results from that query will save into a excel file. Below is the screenshot of the form. Hope this will
    clear the requirements.
    Hello,
    To be honest, this forum is not for coding for anybody.
    You could refer to the suggestions shared above, and if you get any issue when using that code, you could share the code and error with us, we will focus on your code to help you.
    You could separate them into multiple steps, like the following.
    1. Getting the value of any control, like the textbox and combobox or even checkbox.
    2. Execute method inside button click event handler.
    3. Using ado.net to execuate sql query.
    4. Saving data to Excel.
    Then you could have a try step by step, if you get any issue, then post it in another thread with the code and error message.
    Regards,
    Carl
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Query results to a file

    I have a requirement to put the query result in a file(.csv),
    Pls let me know is there a possibility to achieve this using dbms_output package
    Thanks

    859486 wrote:
    I have a requirement to put the query result in a file(.csv),
    Pls let me know is there a possibility to achieve this using dbms_output packageNo. The DBMS_OUTPUT package is almost ALWAYS the wrong package to use. It is the most misunderstood and most frequently abused piece of PL/SQL software. So no - it is not suited in anyway to spool CSV output. In fact, trying it with a large SQLdataset can crash the Oracle server - as memory will be exhausted and the swap daemons will trash CPU utilisation.
    To read or write a physical o/s file - the typical package used is UTL_FILE. It is fairly easy using UTL_FILE to create a CSV file.
    However, there could be far better alternatives. The CSV file may be needed by a web client - in which case the file can be created as a CLOB and provided as a Mime text/csv data stream to a web browser (which usually will automatically open in Excel).
    The CSV file may need to be delivered via e-mail. In which case, the CSV file contents can be delivered via UTL_SMTP to a mail server as an e-mail attachment.
    The CSV file may be needed to be delivered to a remote server. In which case the CSV file can be created as a CLOB and this CLOB can be ftp'ed via PL/SQL to the remote server as a text file.
    So there are many options in creating and delivering a CSV file. Using DBMS_OUTPUT though is not a sensible option - ever.

  • Export query result to txt file

    Hello,
    I'm trying to export a query result to txt file but I facing some problems.
    I'm using the comand below:
    set echo off newpage 0 space 0 pagesize 0 feed off head off trimspool on
    set colsep ,
    spool C:\estados.txt
    select id_estado,cod_estado,nme_estado from tb_estado;
    spool off
    First problem: My select statement is being writen on my estados.txt
    Second problem: The results are being writen with a lot of blank spaces in start of line, for example, instead of write "1,AC,Acre" the line is write as " 1,AC,Acre".
    Third problem: The "spool off" statement is being written on my estados.txt
    How could I solve it?
    Thanks

    1. Works here - what version of SQL*PLUS are you using?
    2. If you want to prevent spaces, you have to write your SELECT like this:
    select id_estado || ',' || cod_estado || ',' || nme_estado from tb_estado;Note: not tested.
    3. See 1.
    C.

Maybe you are looking for

  • Memory trouble on Mac Pro 2009

    Problem description: i have 24 GB of ram but the machine constantly loads up on inactive memory. leaving me with very little free memory. i was thinking of upgrading to latest OS but unsure since i noticed this issue. Below is the info I got from run

  • Create embedded map based on GPX data?

    I have a website that serves up a series of GPS tracks (held as GPX files), each GPS file associated with a different dynamic web page. At the moment I manually create a map with the GPS track shown on it - this is quite time consuming and not partic

  • What version of Adobe is best?

    Do companies usually use CC or CS? Which is best to own and practice and what is the best book to use?

  • How to bind value from one form to another form in ADF Swings

    I am very new to ADF Swings need an Help ! . I have generated two forms one in FILTER FORM and another one is DETAILS FORM. Two parameter are defined in Filter Form 1. Name and 2 .Id and values are entered in textbox and combo box .Based on selected

  • Back up & restore/erase or ignore??

    Hi all. I have ordered a repair for my iPhone. The instructions I recieve say to back up & erase all data from the iPhone before sending it off! However my iPhone has lots of problems (cant hear when making/receiving calls, dodgy home button, phone r