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.

Similar Messages

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

  • 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

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

  • 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

  • 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

  • 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

  • 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

  • Export query results to flat file with dynamic filename

    Hi
    Can anybody can point me how to dynamic export query serults set to for example txt file using process flows in OWB.
    Let say I have simple select query
    select * from table1 where daterange >= sysdate -1 and daterange < sysdate
    so query results will be different every day because daterange will be different. Also I would like to name txt file dynamicly as well
    eg. results_20090601.txt, results_20090602.txt, results_20090603.txt
    I cant see any activity in process editor to enter custom sql statment, like it is in MSSQL 2000 or 2005
    thanks in advance

    You can call existing procedures from a process flow the procedure can create the filename with whatever name you desire. OWB maps with file as target can also create a file with a dynamic name defined by an expression (see here ).
    Cheers
    David

  • Send query results to a file using Toad

    Hello,
    I have a select statement that generates xml rows, and I need to send the results to a file. I am using TOAD VI. The rows generate ok but when I right click and choose the save as option all I end up with is an empty file.
    Is there a way I can just send the results directly to a file instead of to the screen?
    Thanks.

    user11293056 wrote:
    Would you happen to know of a website that shows how to create an xml file using SQL*Plus?
    Thanks.A search of asktom.oracle.com for the following phrase found a couple interesting pages:
    table(xmlsequence(cursor
    On such page is this one:
    http://asktom.oracle.com/pls/asktom/f?p=100:11:1074646661177911::::P11_QUESTION_ID:4061080732051
    As an experiment, you might take a look at the output of the following (replace SELECT * FROM MY_TABLE_HERE with your SQL statement):
    SELECT
    FROM
      TABLE(XMLSEQUENCE(CURSOR(
        SELECT
        FROM
          MY_TABLE_HERE
       )));Charles Hooper
    IT Manager/Oracle DBA
    K&M Machine-Fabricating, Inc.

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

  • Need to write query results to .xls file

    Hi All,
    My requirement is ,when i run a query from sqlplus the results should be copied to a excel sheet.But i am not able to generate the file in the correct format.Could some body please help on this..
    Thanks in advance
    Thanks
    [email protected]

    Could some body please help on this..I am sorry to see that GOOGLE, SEARCH & HELP are broken for you.
    Please be patient while repairs are completed.
    Additional information will be posted when it becomes available.

  • Saving query results to a file

    How do i store the results of the a query into a file? Following is the query i am trying to use...
    Thanks.
    StringBuffer sb = new StringBuffer().append("SELECT ").append(select)
                        .append(" FROM ").append(DISTRIBUTOR_TABLE);
              if (where != null && 0 < where.length()) {
                   sb.append(" WHERE ").append(where);
                   if(hasState){
                        sb.append(" UNION ");
                        sb.append("SELECT ").append(select).append(" FROM ").append(DISTRIBUTOR_TABLE);
                        sb.append(" WHERE ").append("ID =(select DISTRIBUTOR from statesApply where STATE = '?' ");
              }

    1. set up a db conection 9set the driver name, server url, port, login, password, etc)
    2. open the connection
    3. execute the query (using statement or preparestatement)
    4. iterate over the resultset
    a) store the data from the result set in an object
    5. close the resultset, statement, connection
    6. write to a file
    a) depends on how you want to store the data (if text.use PrintWriter)
    check out the Sun website for tutorial on using JDBC (database..it's pretty good and easy..you'll get started in no time)
    also check out the IO tutorial (specifically on PrintWriter to write String to a text file)

Maybe you are looking for

  • Itunes/Iphone 4s replaced - Music, voice memos and playlist missing and or deleted

    Backed up old phone, had phone replaced from Apple Store.  they told me to restore from back up at home computer.  My playlists are gone, my voice memos are all gone, losing memos and pictures on the phone.  Can't play any music on the computer eithe

  • Vacancy cannot be edited

    Hi experts could somebody telling me, why by one case i am not able to update a vacancy (the pencile is marked as gray). I all other cases the pencile is yellow, so thta i can update my created vacancies. The end date is open, and status is set to ap

  • Auto Select Layer - where is it?

    I have "auto select" turned on for the Move Tool and I click on a layer. How can I get Photoshop's Layer palette to scroll what I selected?  I'm having to scroll up and down a lot trying to find my highlighted layer.

  • Live Type Not Responding

    Hi Sirs. When I try and open Livetype, after about 20sec. The Program hangs and does not respond. Any ideas. Thanks Jon

  • I have iWeb 3.0.4 on my computer,

    can I build a website and upload it to somewhere?  It says mobile me, but that's gone.  Help, a rookie.