Write big query results into a file  ? ?  ?

Hi all,
The problem is: I want to write a simple query results into a file. I have no idea how to do that. Only thing I know is utl_ functions. Please advise GURUS how can I use them for big queries. Any example will be really appreciable.
Thank you in advance.
Message was edited by:
v838

hi,
i´ld do it like that:
filedir     varchar2(30):= '/usr/frajo/';
filename     varchar2(30):= 'file.txt';
fhandle     utl_file.file_type;
cursor x is
select ... (what ever)
begin
     fhandle := utl_file.fopen (filedir, filename,'a');
     open x;
     loop
          fetch x into (what ever)
          exit when x%notfound;
          utl_file.put_line (fhandle,'text and you results');
     end loop;
     utl_file.fclose(fhandle);
end;
happy xmas. franz

Similar Messages

  • Write the ldapsearch results into a file

    We are using ldapsearch from the command line and want to write the search results into a file. How can we do this?

    What OS are you using - If Unix / Linux then use the standard redirection > or >> facility.

  • Export query results into .csv file?

    Hello I have a T-SQL script that gets row counts for a specified date range and then needs to loop (by incrementing +1 day to get the next day's counts) for a large date range.  I'm aiming to output & append each query results day counts
    into a .csv file via a SQL Agent job since this will take quite a while to complete.
    Would using the following as an example template...
    INSERT INTO OPENROWSET('Microsoft.ACE.OLEDB.12.0','Text;Database=D:\;HDR=YES;FMT=Delimited','SELECT * FROM [FileName.csv]')
    SELECT Field1, Field2, Field3
    FROM DatabaseName
    ...be the method or something else?
    If this is good to use I've tried running this but get the following error:
    Msg 7357, Level 16, State 2, Line 76
    Cannot process the object "SELECT * FROM [FileName.csv]". The OLE DB provider "Microsoft.ACE.OLEDB.12.0" for linked server "(null)" indicates that either the object has no columns or the current user does not have permissions
    on that object.
    Thanks in advance.

    Hi Techresearch7777777,
    The error in your post says that the file FileName.csv has to be created with the column names in the first row. Like:
    Field1,Field2,Field3
    Either you can create a schema.ini file under the same folder:
     [FileName.csv]
     Format=CSVDelimited
     ColNameHeader=False
     Col1=Field1 [DataType]
     Col2=Field2 [DataType]
     Col3=Field3 [DataType]
    For the [DataType],you can reference
    Schema.ini File (Text File Driver)
    If you have any question, feel free to let me know.
    Eric Zhang
    TechNet Community Support

  • 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.

  • Loading Query results into a file/cache

    Hi,
    We have a Query which returns huge volume of data.
    spooling all the records will take a lot of time.
    Is there any other way through which we can load the results of this huge query into Oracle's Cache / File
    Tables used in the Query are Range hash composite partitioned tables.
    But, in the query only a single partition is being used.
    Suggest any method to acheive the same.
    Thanks,
    Kris.

    Alex Nuijten wrote:
    .... Blu, you're not suggesting that OP use the database what it's good for, are you?.... But then OP would loose database-independence...
    :)Ermm.... darn it, you're right, what was I thinking. ;)
    Anyway, should there really be a requirement to output the data to a file, then there's nothing wrong with using UTL_FILE...
    SQL> ed
    Wrote file afiedt.buf
      1  declare
      2    v_fh UTL_FILE.FILE_TYPE;
      3  begin
      4    v_fh := UTL_FILE.FOPEN('TEST_DIR','output.txt','w',32767);
      5    DBMS_OUTPUT.PUT_LINE(TO_CHAR(SYSDATE,'HH24:MI:SS'));
      6    FOR i IN (SELECT * FROM large_tbl)
      7    LOOP
      8      UTL_FILE.PUT_LINE(v_fh,
      9                        TO_CHAR(i.large_id,'fm999999')||','||
    10                        i.large_area||','||
    11                        TO_CHAR(i.large_line,'fm999999')||','||
    12                        TO_CHAR(i.datelogged,'DD/MM/YYYY')||','||
    13                        TO_CHAR(i.large_flag,'fm9')||','||
    14                        '"'||i.large_text||'"');
    15    END LOOP;
    16    DBMS_OUTPUT.PUT_LINE(TO_CHAR(SYSDATE,'HH24:MI:SS'));
    17    UTL_FILE.FCLOSE(v_fh);
    18* end;
    SQL> /
    09:01:08
    09:05:20
    PL/SQL procedure successfully completed.
    Elapsed: 00:04:12.47
    SQL> select count(*) from largetbl;
      COUNT(*)
       6637873Over 6.5 million records in 4 minutes 12 seconds, and that's with data formatting.

  • 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.

  • How to output a query results into a text file

    How to output a query results into a text file instead of outputing it to the screen..
    is there a way for us to write a SQL query which specifies to output the query results to a text file.
    Pls let me know how to do it
    Thanking u in advance
    regards
    Muraly

    Muraly,
    If you are using SQL*Plus 8.1.6 or later, you can also spool output to a file in HTML format, eg
    SET MARKUP HTML ON SPOOL ON PREFORMAT OFF ENTMAP ON
    SPOOL c:\temp\report.html
    SELECT DEPARTMENT_NAME, CITY
    FROM EMP_DETAILS_VIEW
    WHERE SALARY>12000;
    SPOOL OFF
    SET MARKUP HTML ENTMAP OFF
    In iSQL*Plus 9.0.1 (the browser-based interface to SQL*Plus) onwards, you can also send the HTML output to a new web browser window, or an html file -- much easier than the command line method.
    Alison

  • 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.

  • Query result to ASCII file output

    Seems like there SHOULD be some rediculously simple solution
    to this - but I sure haven't found it yet! I have a query which
    produces the a varying number of columns (based on a multi-select
    cfselect) which I need to output to a comma delimited ASCII (.TXT
    or .DAT or .CSV file). I have all the steps worked out when the
    number of columns and their names are known, but I need to make
    this variable. First choice would be to be able to just "DUMP" the
    query result into a text file. CFDUMP can send results to a text
    file, but NOT in comma delimited format, and with all kinds of info
    besides just the basic data. (NOT good!) Second choice, since the
    "append to text file" uses an output property that expects a comma
    delimited string variable would be to use CFLOOP to loop thru the
    rows in the query and put them (a row at a time) into a variable,
    then use that variable for the file append. Problem is I can't find
    a way to just say "send *ALL* to the string variable. Every example
    I have been able to find includes specifying the column NAMES when
    doing anything with a row in the query result!!! Short of a brute
    force series of if/then statements that specify EACH POSSIBILITY
    (in this case 60 - 75 of them, and the number WILL GROW!) I haven't
    been able to find a solution. There's GOTTA BE A WAY!!!!! :)

    auntiealias
    > I tried that, but as far as I could figure you still
    have to have a specific column name
    Look at the udf more closely. If you read the documentation
    it states all of the parameters are optional, except the query. So
    if you do not supply column names, the function will use the
    columnList variable to determine the names of the columns in the
    query. If you look at the actual code, notice it uses array
    notation to extract the values (not evaluate) .
    ... (code to create query) ...
    <!--- pass in the query object only ---->
    <cfset test = QueryToCSV2( data )>
    http://cflib.org/index.cfm?event=page.udfbyid&udfid=1197
    > I have a cfselect with multiple set to "yes" and the
    selections are "which columns of
    > data do you want to see?"
    Hopefully you are not using the raw form value directly in
    your sql, because that is a sql injection attack just waiting to
    happen.

  • Http 404 error exporting query result into Excel.

    Hello. I'm getting an Http 404 The webpage cannot be found" error when trying to export any APEX application's query results into Excel (Application Express 3.2.1.00.10). This was working fine before. Nothing changed with our APEX application. I've been always using I.E. Version 7.0.5730.11 with no problems. I've reset the I.E. defaults and still the problem exists. I've downloaded Mozilla Firefox and the problem does not happen. However, I would like to know why my I.E. still gets this error? Any feedback or suggestions would greatly be appreciated. Thanks for your time.

    My EI settings are as follows:
    Tools -> Internet Options -> Security
    All Three: Internet, Local Intrarnet, and Trusted Sites ... at Custom Level have the following settings:
    Downloads:
    Automatic prompting for file downloads = Enable
    File download = Enable
    Font download = Enable
    Problem still exists.
    Thanks for the help.... any additional feedback or suggestions would greatly be appreciated. Thanks for your time.

  • 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.

  • 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

  • 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.

  • Is there a way to combine their query results into a single function

    say I have a bunch of functions that return a query:
    <cffunction name="getDeals" access="remote"
    returntype="query">
    <cffunction name="getDeals2" access="remote"
    returntype="query">
    is there a way to combine their query results into a single
    function that returns a struct of the various results?

    Umm, it's probably more suited to an array - effectively
    making it into a list of queries. You'd then loop the array and
    output each.
    I use a similar approach when creating system messages to the
    user. Most of my functions that are called do their bit, then at
    the end call another function I call "messages". This function
    grabs whatever my function sends and appends it to a messages
    array.
    This way enables me to output a long list of messages -
    because I could be calling several functions at the same time. If I
    just output a message from each function, each one would overwrite
    the other. So I'd get one message at a time.
    Immediately after it's output, I then destroy the message
    array so that old messages aren't kept inside of it.
    Mikey.

  • 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

Maybe you are looking for