Export query to csv file

I am almost new to Oracle, been a decade since I last worked on it. I have query over multiple tables. I need to run the query daily and get a csv file out of it. How sure how to do it. Can anyone please help? In the csv file I need no headers etc. just comma separated rows.
I found this link which is very helpful, however, no matter what I try, the output file shows the query too. How do I make sure the output file has just the data and not the query?
http://stackoverflow.com/questions/643137/how-do-i-spool-to-a-csv-formatted-file-using-sqlplus
Edited by: 857833 on May 10, 2011 9:00 AM

This is getting very frustrating. Below is what I type in my sql plus window.
set colsep ','
set echo off
set feedback off
set linesize 1000
set pagesize 0
set sqlprompt ''
set trimspool on
set headsep off
spool "FULLPATHTOOUTPUTFILE"
@"FILEWITHQUERY.SQL"
spool off
This creates the output file, where first line is @"FILEWITHQUERY.SQL"
then shows the result set rows, the last row in the file is "spool off"
Can you please show me an example that works for you? I never imagined generating a text file from tables is this hard. :((

Similar Messages

  • Query to CSV file

    Hi,
    Is there a way to execute the query and save it in application server as csv format .  I've aleardy tried couple of the options -
    RSCRM_BAPI - due to complex restrictions in the query, the output is not consistant.
    Information Broadcasting - can either store in KM folder(portal) or email, not in application server.
    I have gone thro the couple of forum threads wr - abap to csv(Execute BW query using ABAP Part III), writequery, RRW3_GET_QUERY_VIEW_DATA ..   The abap with direct output to application server will be interested.
    Thanks
    Sreedh

    Hi,
    I hope it will help.
    Exporting as a CSV File 
    In order to process a query executed in a Web application further, you have to export the query as a CSV file or MS Excel 2000 file.
    Prerequisites
    ·        You have executed a query in your Web application and want to display it in a different format and continue processing the query.
    ·        To export the data to an Excel file, you have opened the BEx Analyzer
    Procedure..
           1.      From the context menu (left mouse-click on the text of a characteristic, characteristic value, structural component, description of exception, description of condition), choose Export As.... ® CSV File or Export As.... ® MS Excel 2000 File. The system exports the data into a CSV file or an MS Excel 2000 file.
    Export to MS Excel files from MS Excel 2000 is supported.
           2.      If you choose Export As...® CSV File, the query is displayed in CSV format (comma separated value). The numerical values of the query are displayed in a list that is separated with commas. The numerical values context, formatting (for example, displaying exceptions) and the filter data are available in the CSV file. You cannot navigate further with BW functions.
    Thanks
    Hema

  • OBIEE 11g - issue when export to a csv file

    Hello,
    I have an issue when I try to export to a csv file a report having numeric feild, when I export and open the file in notepad the trailing zeros to the right of decimal points do not show up. When export to another formats (such as excel, pdf) the trailing zeros appears correctly. e..g, 100.00 appears as 100, 100.50 appears as 100.5.
    Do you know what can be done in order to have trailing zeros to the right of decimal points to appear in a csv?
    Thanks

    This is a bug see below.
    Bug 13083479 : EXPORT DATA TO CSV FORMAT DOES NOT DOWNLOAD EXPANDED HIERARCHICAL COLUMNS
    Proposed workaround : OBIEE 11.1.1.5: Pivot Table Report Export To Csv Does Not Include Hierarchical Data [ID 1382184.1]
    Mark if answered.!
    Thanks,
    SVS

  • How to query a csv file

    Hello I am new to cold fusion.
    I am wondering if there is a way to query a csv file using a read from cffile? Currently I have it setup as a cffile read and then I try to query the file using cffquery. Obviously this doesn't work because I have to set a datasource. Is there anyway to do this or any way to set a csv file as a data source? Any help or direction would be greatly appreciated.
    Thanks.

    You would have to read in the csv and create a query using QueryNew(). Once you have the csv in a query format, then you can perform query of queries to do most anything you want on the data. There is probably code already written out there to do the csv to query, you just need to find it. The query of queries is in the documentation. The only gotcha is that query of queries sorting and matching is case sensitive. Hope this helps.

  • How do I expand a ActiveDirectorySubnetCollection so I can view all elements and export to a CSV file?

    Hello,
    In the following, I list SiteName, Location, Subnets, and Severs, however I don't see all the servers or the subnets, presumably because Subnets are an ActiveDirectorySubnetColletion and Servers are a ReadOnlyDirectoryServerCollection.  So I want to
    expand this property so I can see all the elements of the collection, or array.  I've tried the Select-Object -ExpandProperty, but I get an error due to -ExpandProperty looking for a string.
    Any suggestions on how to expand both the Subnet and Server collections so I can see all elements and I can export to a CSV file?
    [cmdletbinding()]
    param()
    $MyArray = @()
    $Sites =[System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest().Sites
    foreach ($Site in $Sites) {
    $obj = New-Object -Type PSObject -Property (
    "SiteName" = $Site.Name;
    "SiteLocation" = $Site.Location;
    "SubNets" = $Site.Subnets;
    "Servers" = $Site.Servers
    $Obj | Sort $Site.Name | FL
    $MyArray += $obj
    $MyArray | export-csv -path $env:HOMEPATH\SitesSubs.csv -NoTypeInformation
    Thanks for your help! SdeDot

    I've got a script that might help you out:
    http://gallery.technet.microsoft.com/scriptcenter/Convert-OutoutForCSV-6e552fc6
    Blog reference:
    http://learn-powershell.net/2014/01/24/avoiding-system-object-or-similar-output-when-using-export-csv/
    Boe Prox
    Blog |
    Twitter
    PoshWSUS |
    PoshPAIG | PoshChat |
    PoshEventUI
    PowerShell Deep Dives Book

  • Exporting data to csv files

    Please can you help an Oracle newcomer?
    Below is a script (which I took from the forums) that I used to
    run in Lite to export data to a csv file.
    As you can see I am having problems with running the same file
    in 8i - It starts off OK i.e. asking for the name of the table
    but then, instead of completing the full script it executes a
    few lines then keeps asking me for the name of the table. I
    suspect there is something wrng in my environment settings
    (Comments ON etc.) but I have checked everything with no success.
    Any help would be much appreciated as this is a really useful
    script which I use the whole time.
    Thanks very much for your help.
    Regards
    Andrew
    SQL>
    1 SET ECHO OFF
    2 SET FEEDBACK OFF
    3 SET HEADING OFF
    4 SET PAGESIZE 0
    5 SET TIMING OFF
    6 SET VERIFY OFF
    7 ACCEPT name_of_table PROMPT 'Enter the name of the table
    you wish to convert: '
    8 SPOOL query.sql
    9 SELECT 'SPOOL ' || UPPER ('&name_of_table') || '.txt'
    10 FROM DUAL;
    11 SELECT 'SELECT ' || column_name
    12 FROM all_tab_columns
    13 WHERE table_name = UPPER ('&name_of_table')
    14 AND column_id = 1;
    15 SELECT '|| '','' || ' || column_name
    16 FROM all_tab_columns
    17 WHERE table_name = UPPER ('&name_of_table')
    18 AND column_id > 1;
    19 SELECT 'FROM ' || UPPER ('&name_of_table') || ';'
    20 FROM DUAL;
    21 SELECT 'SPOOL OFF'
    22 FROM DUAL;
    23 SPOOL OFF
    24* START query
    25 /
    Enter value for name_of_table: new_table
    old 9: SELECT 'SPOOL ' || UPPER ('&name_of_table') || '.txt'
    new 9: SELECT 'SPOOL ' || UPPER ('new_table') || '.txt'
    Enter value for name_of_table: new_table
    old 13: WHERE table_name = UPPER ('&name_of_table')
    new 13: WHERE table_name = UPPER ('new_table')
    Enter value for name_of_table: new_table
    old 17: WHERE table_name = UPPER ('&name_of_table')
    new 17: WHERE table_name = UPPER ('new_table')
    Enter value for name_of_table: New_table
    old 19: SELECT 'FROM ' || UPPER ('&name_of_table') || ';'
    new 19: SELECT 'FROM ' || UPPER ('New_table') || ';'
    SET ECHO OFF
    ERROR at line 1:
    ORA-00922: missing or invalid option

    Thanks for your help - problem solved I was using Run sql file
    instead of Start sql file - oops!

  • Powershell script to search a network drive for .mdb files and export them to CSV file

    Hello all,
    I'm trying to search one of our network drives for old .mdb files, I want to write the name, location and date last modified to a csv file.
    Get-WmiObject -Class CIM_DataFile -Filter "Drive='S:' And Extension='mdb'
     AND ObjFile.drive
     AND objFile.FileName
     AND objFile.FileSize
     AND objFile.LastWriteTime" |
    Export-CSV c:\mdb_search\mdbfiles.csv\
    Obviously this isn't working or I wouldn't be posting.  I've tried many different examples from the net with no joy for now.
    Thanks for any help you can offer.

    Thanks, that did the job.
    Cheers, you're welcome.
    How do I get the powershell cursor to return to C:> ?
    Should I use "exit" or "break" ?
    Neither, the console will return to a prompt when the search has been completed.
    Don't retire TechNet! -
    (Don't give up yet - 13,225+ strong and growing)

  • Need help with query from .csv file

    I am trying to import a csv file with only 1 column in it.
    The column will only contain a 9 digit ID number. I want to read
    the file then use the contents to query a table to get the names
    and other information and display it. Here is what I have so far:
    <cffile action="read" file="#form.FiletoUpload#"
    variable="csvfile">
    <cfloop index="index" list="#csvfile#">
    <cfquery name="massimport" datasource="data1">
    SELECT * FROM IDTable
    WHERE CardNumber = ('#csvfile#')
    </cfquery>
    </cfloop>
    <cfoutput>#Name# #ID# #Site#</cfoutput>
    I get no errors but I am not getting any results. Just a
    blank page. Does anyone know how to query directly from a csv
    import? Thanks.

    You need to convert your file to a list somehow. Not sure if
    this is the most efficient way but, you can use the cfhttp tag to
    produce a query. Then your where clause becomes,
    where cardnumber in (#quotedvaluelist(query.column)#)
    and you won't need a loop.

  • How to export data to .csv file  ?

    Hi guys, I know this topic is covered many times in this forum. How do I export my table data to a csv file when my data already has some , (commas) in it. For example, I have two columns in a table, ID and DESCRIPTION. The DESCRIPTION column has data which has , (commas) in it. When I export the data using the following script, I see multiple columns in my excel file as DESCRIPTION has data with commas and each part of it is shown as a separate column in excel sheet.
    set heading off
    set echo off;
    set pause off;
    spool tbl_account.csv;
    select To_Char(ID)|| ',' || To_Char(Description) From tbl_account;
    spool off;
    Thanks in advance

    Have you thought about putting those values between quotation marks?
    "test,test" for example would end up in one cell.
    C.

  • Saving result from query into CSV file

    Hi folks,
    in our application we're generating pages source using general packages (like htp, owa_util, ...). and in this part I'm a really beginner.
    I want to modify source one of our page, I want to add functionality to enable save result from query (cursor) into CSV file, to enable user choose place where generated file will be created and also change file name.
    I searched this forum and I found procedure, that could be useful:
    procedure p_getcsv is
    cursor cur is
           select 'a1' col1, 'b1' col2, 'c1' col3 from dual
       union  select 'a2' col1, 'b2' col2, 'c2' col3 from dual
       union  select 'a3' col1, 'b3' col2, 'c3' col3 from dual;
       begin
            -- Set the MIME type
            owa_util.mime_header( 'application/octet', FALSE );
            -- Set the name of the file
            htp.p('Content-Disposition: attachment; filename="test.csv"');
            -- Close the HTTP Header
            owa_util.http_header_close;
            -- Loop through all rows in EMP
            for x in cur
            loop
                -- Print out a portion of a row,
                -- separated by commas and ended by a CR
                 htp.prn(x.col1||','|| x.col2||','||x.col3|| chr(13));
            end loop;        
       end;What peace of code should I add to procedure that is generating web page to enable calling this procedure and whole saving process?
    Can anybody help me with this?
    Many thanks,
    Tomas
    Message was edited by:
    Tomeo

    Hi Marc,
    thanks for reply, problem is that I'm not using APEX application, I'm just generating web page code straight using oracle general packages.
    But I found this solution (maybe some tunning will be good):
    In page where I want to display Download i have
      begin
             htp.anchor2 (
                           curl  =>  ... .p_getcsv'||'?term=2005&crn=123,
                           ctext => 'Download Class List'
             HTP.br;
          end;
    ...si I'm calling p_getcsv procedure:
      procedure p_getcsv( term  IN stvterm.stvterm_code%TYPE DEFAULT NULL,
                           crn   IN sirasgn.sirasgn_crn%TYPE DEFAULT NULL) is
       v_length      NUMBER;
       v_file_name   VARCHAR2 (2000);
       temp_blob  blob;
       line RAW(32767);
       begin
             DBMS_LOB.CREATETEMPORARY(temp_blob, TRUE);
             FOR i IN 1..6  LOOP
                line := UTL_RAW.CAST_TO_RAW(i||','||term||','||crn||',AAA,BBB,CCC'||chr(10));
                DBMS_LOB.WRITEAPPEND(temp_blob, LENGTH(UTL_RAW.CAST_TO_VARCHAR2(line)), line);
             END LOOP;
              v_file_name := 'ClassList.csv';
              v_length  := DBMS_LOB.getlength (temp_blob);
              -- set up HTTP header
                 -- use an NVL around the mime type and
                 -- if it is a null set it to application/octect
                 -- application/octect may launch a download window from windows
               OWA_UTIL.mime_header (NVL ('csv', 'application/octet'), FALSE);
               -- set the size so the browser knows how much to download
               HTP.p ('Content-length: ' || v_length);
               -- the filename will be used by the browser if the users does a save as
               HTP.p (   'Content-Disposition:  attachment; filename="'
                  || REPLACE (REPLACE (SUBSTR (v_file_name,
                                               INSTR (v_file_name, '/') + 1
                                       CHR (10),
                                       NULL
                              CHR (13),
                              NULL
                  || '"'
                 -- close the headers
                 OWA_UTIL.http_header_close;
                -- download the BLOB
                 WPG_DOCLOAD.download_file (temp_blob);
                 -- release temporary blob
                 dbms_lob.freetemporary(temp_blob);  
       end;Regards,
    Tomas

  • How to export data to csv file on a scheduled basis

    Hi,
    I'm trying to do something that should probably be simple but I just can't figure it out.
    I have an existing MS SQL database (2008 R2). I have a very simple SQL script. I need to run this script on a daily basis and save the results as a .csv file.
    I've tried creating a job in SQL Manager - that didn't work. Then I found a tutorial that had me use MS Visual Studio... couldn't get that to function either.
    Can someone help me understand what program I should be using, and how to go about creating this as a task / job that can run on a scheduled basis?
    Thank you!
    Chris

    Hi, you can follow the below steps to get your work done -
    Create a batch file (.bat) and dump the following text into it
              sqlcmd -S myServer -d myDB -E -Q "select col1, col2, col3 from SomeTable" -o "MyData.csv" -h-1 -s"," -w 700
              Replace myServer with your server name,
    myDB with your Database name and then replace the query with your actual query.
             -h-1 removes column name headers from the result
             -s"," sets the column seperator to ,
             -w 700 sets the row width to 700 chars (this will need to be as wide as the longest row or it will wrap to the next line)
    Save the batch file and the schedule it as per your requirement.
    Hope, that helps.
    -Vinay Pugalia
    If a post answers your question, please click "Mark As Answer" on that post and
    "Mark as Helpful".
    Web : Inkey Solutions
    Blog : My Blog
    Email : Vinay Pugalia

  • HT204150 export contacts into csv file

    Does anyone know how to export contacts either from iCloud or directly from the iPhone into a CSV file?

    Does anyone know how to export contacts either from iCloud or directly from the iPhone into a CSV file?

  • Automating Export/Import of CSV Files

    Thought I would ask here for any advice or suggestions because my knowledge is lacking in this area a bit.
    What I need:
    An automated process, whether it be 3rd party s/w or a cron job, that can export a few tables to csv's and then xfer the file to another server.
    At this point i will need a process that can take that csv and automatically load it into a different oracle DB.
    Any suggestions on good software to use or scripts to run would be a great start to my research. thanks

    Hello,
    You can simply write some sql scripts to generate csv file and you can connect from remote server to run this sql scripts and it will generate csv file on target server. What you need to do is configure your tnsnames.ora to connect to your source server from target server. Meaning from target server you should be able to sqlplus in.
    #target server
    $> sqlplus username/password@source_db
    sqlplus > test.sqlNow you can write shell script and here is a function which you can extend and call different sql script to generate csv file.
    function exesqlfile{
      typeset sqlfile=$1
      if [ ! -f $sqlfile ]
      then
           echo "sql extraction file doesn't exist....";
           echo "Exiting..."
           exit 1;
      fi
      echo "
        set feedback off
        set verify off
        set heading off
        set pagesize 0
        whenever sqlerror exit 1
        whenever oserror exit 2
        @$sqlfile
        exit 0
      " |  sqlplus -s $username/$password@$source_db
        tbl_x_ret_code=$?
        if [ $tbl_x_ret_code -eq 0 ]
        then
             return 0;
        else
             return 1;
        fi
    }Regards
    OrionNet

  • Sql query on csv file

    hello,
    I am looking for a code/package/driver for SQL queries on .csv files.
    The driver should be able to deal with both local files and remote
    files.
    The best if it will be able to use stream/reader.
    Does anyone familiar with something like that?
    Thank you,
    Asi

    I think theirs an ODBC driver that supports this, but that's obviously a second-class solution at best.
    The second closest thing to this is HSQLDB. It usually uses it's own format but can be used to reference other files as well IIRC

  • Newbie: BW Export to Excel/CSV file destination and file name

    Is it possible to control where the export of a BW web query is sent by appending the url with some tag voodoo? Also, can I create the file name of the exported file? I figured out how to kick off the export process, but haven't found any code to control the export destination or file name. I wish to skip over the save dialog and write the file to a specific location.

    Hello John,
    BW provides several ways to export data. Please look into Open Hub for example.
    Other options include Information Broadcasting in SAP NetWeaver '04 or MDX, XML Webservices, or OLAP BAPI.
    Regards,
    Marc
    SAP NetWeaver RIG, US BI

Maybe you are looking for

  • New in Adobe forms

    Hi all, i want to configure Adobe Document Service for using digital signature on all print programs. If anyone has implemented it, please provide docs/steps to configure ADS. Please guide me on this matter regards Asish

  • How to use a custom comparator in a TableSorter?

    Hi, I want to use a custom comparator for sorting a table by a specific column. As you possibly know, the constructor for the TableSorter class looks like this: TableSorter(IWDTable table, IWDAction sortAction, Map comparators); As Map is an Interfac

  • Hyperion

    Hi 1.What r the general maxl commands used in real scenario? 2.How to do the Batch Scripting? 3.how to take general backup process for the database and what are the individual backups to take? 4.what kind of optimization techniques we use generally i

  • Http request error on safari

    http request error on safari what is the solution?

  • Can't configure CSV pserver on Leopard

    I had a CVS repository installed on my PowerMac G5 that I could access remotely from other computers on my network. I recently upgraded the system to Mac OS X 10.5.1 and now the repository is not working. I found a web site that showed how to create