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

Similar Messages

  • Write Query Results into a text file

    Hello All,
    In SAP B1 Query Generator I'm trying to write the results of a query into a text file (.txt). I've tryed with queryout but it doesn't work.
    What I want is something like this:
    SELECT * FROM TABLE queryout "C:/textfile.txt"
    Any sugestions?
    Thanks in advance,
    Miguel Barbosa

    Hello All,
    Since yesterday and due to your help, I've found how to solve my problem.
    This post is only to share with you and with the others users of Expert Forums how to Write the results of an SQL Query in SAP Business One to a Text File without making it by exportation.
    Requested Text File by customer:
    Document type in R/3 If Invoice -- 'Z100' - Position 1 to 4 - 4 characters
    Supplier Code -- dbo.Table.CardCode -- Position 5 to 15 - 10 characters
    Item Code -- dbo.Table.ItemCode -- Position 11 to 25 - 14 characters
    Client Code -- dbo.Table.CardCode -- Position 26 to 36 - 10 characters
    Client Name -- dbo.Table.CardName -- Posiiton 37 to 100 - 63 characters
    Fixed Blank Field -- ' ' -- Position 101 to 120 - 19 blank spaces
    Quantity -- dbo.Table.Quantity -- Position 121 to 140 -- 19 characters
    Unit Price -- dbo.Table.PriceBefDi -- Position 141 to 160 -- 19 characters
    If Invoice Fixed identifier -- 'Z01' -- Position 161 to 163 -- 3 characters
    Fixed Blank Field -- ' ' -- Position 164 to 220 -- 56 characters
    Document Date -- dbo.Table.DocDate -- Position 221 to 229 - 8 characters
    Delivery Date -- dbo.Table.ActDelDate -- Position 230 to 238 - 8 characters
    Sales Order Number - dbo.Table.DocNum -- Position 239 to 260 - 21 characters
    Delivery Number - dbo.Table.DocNum -- Position 261 to 282 - 21 characters
    Follows the code:
    EXEC master..xp_cmdshell'bcp
    SELECT DISTINCT
    ''Z100''
    + ''ZP00002091''
    + IsNull(Convert(nVarChar(44), Cast(T0.DocNum As Numeric(38, 0))), '''')
    + ''PTAP''
    + ''          ''
    + ((LTRIM(RTRIM(T1.U_NumConc)))) + SPACE(10-LEN(LTRIM(RTRIM(T1.U_NumConc)))) + ((LTRIM(RTRIM(T3.BaseRef)))) + SPACE(10-LEN(LTRIM(RTRIM(T3.BaseRef))))
    + ''                    ''
    + ''Z02''
    + CONVERT(varchar(10), T1.ActDelDate, 112)
    + CONVERT(varchar(10), T0.DocDate, 112)
    + ''    ''
    + IsNull(Convert(nVarChar(44), Cast(T1.BaseRef As Numeric(38, 0))), '''')
    + ((LTRIM(RTRIM(T1.ItemCode)))) + SPACE(18-LEN(LTRIM(RTRIM(T1.ItemCode))))
    + ''0'' + REPLACE(SPACE(12-LEN(CONVERT(varchar(12), CAST(T1.Quantity AS NUMERIC (38,3))))),'' '',''0'') + REPLACE(((LTRIM(RTRIM(CONVERT(NUMERIC(38,3),T1.Quantity))))),''.'','''')
    + ''0'' + REPLACE(SPACE(12-LEN(CONVERT(varchar(12), CAST(T1.PriceBefDi AS NUMERIC (38,2))))),'' '', ''0'') + REPLACE(((LTRIM(RTRIM(CONVERT(NUMERIC(38,2),T1.PriceBefDi))))) ,''.'','''')
    + ''ZPHA''
    + ''          ''
    + ''  ''
    + ''                         ''
    + ((LTRIM(RTRIM(T4.CardName)))) + SPACE(69-LEN(LTRIM(RTRIM(T4.CardName))))
    + ''                        ''
    + CONVERT(varchar(10), T0.DocDate, 112)
    + ''               ''
    FROM
    JFOTST.dbo.OINV T0
    INNER JOIN JFOTST.dbo.INV1 T1 ON T0.DocEntry = T1.DocEntry
    INNER JOIN JFOTST.dbo.ODLN T2 ON T2.DocNum=T1.BaseRef
    INNER JOIN JFOTST.dbo.DLN1 T3 ON T3.DocEntry=T2.DocEntry
    INNER JOIN JFOTST.dbo.OCRD T4 ON T1.U_NumConc=T4.AddId
    WHERE T0.CardCode=''C52''
    queryout "c:\text1.txt" -c -T -x'
    Note that in this code everytime you need to use the symbol ' you have to doble it like ''Fixed Text''.
    Be aware that there is one UDF so if you try to make this query run in your SB1 you will have to create a UDF called U_NumConc in the document lines.
    Database usage:
    JFOTST.dbo.OINV T0
    JFOTST.dbo - Database Name.
    OINV - Table
    T0  - Alias
    For any doubts I'll be available to help.
    Once again thank you very much for all your help.
    Together we are stronger!
    Kind Regards,
    Miguel Barbosa
    Edited by: Miguel Barbosa on Aug 18, 2009 12:09 PM
    Edited by: Miguel Barbosa on Aug 18, 2009 12:10 PM

  • How can I export the query result into access(*.mdb) file?

    Dear all:
    I want to export the query result displayed in jsp into excel file
    and access file. And I have exported the result into excel format successfully, only one line should be added in the head of Jsp:
    <%@ page contentType="application/vnd.ms-excel; charset=gb2312" %>
    But how can I export it in access(*.mdb) file? I have replaced "excel"
    with "access". But it can't achive my goal.
    What should I do to achieve my goal?
    Thanks!

    The only reason your Excel export works is that Excel knows how to interpret comma separated values as an input file format. Access has no such beast.
    If you absolutely must provide info in an mdb, one solution would be to create an ODBC datasource pointing to an empty mdb, then push data into it using the jdbc:odbc bridge, then make a copy of the file and stream it down to the browser. You may run into some ugly file locking items here - set the ODBC connection so it is not shared, and that might help.
    This one is going to be ugly.
    I suppose another approach would be to write a simple VB applicatin that uses automation to create an MDB, then stream that file down to the browser from your servlet. That would almost certainly be faster than the ODBC approach.
    - K

  • Output query result to a text file in ORACLE

    I Need a procedure for generating output query into text file in Oracle.
    for Example,
    A table called Tab1
    the columns are c1,c2,c3,c4,c5.
    I want to store the data in text file in...
    First row as a column name & then, appear the records in second row onwards...
    c1|c2|c3|c4|c5.
    Please kindly provide the solution for this ASAP.

    In case you are using Oracle 9i or higher you should better create a DIRECTORY rather then setting utl_file_dir,e.g.
    SQL> CREATE DIRECTORY log_dir AS '/appl/gl/log';
    SQL> GRANT READ ON DIRECTORY log_dir TO DBA; http://download-west.oracle.com/docs/cd/B10501_01/appdev.920/a96612/u_file.htm#ARPLS069

  • How to upload the web query result  to CSV/Text file

    Hi,
    Kindly help me on the following.
    1)       I have info-provider (IP), which has info-objects "company code" and "supplier".
    2)       I built a query by putting company-code with a variable in free-charateristics and supplier-code in row.
    3)       When I run this query, it will ask company-code as input and the result will be filtered using company-code.
    4)       For this query, I created a web-template and assigned data-provider to display the data on the web.
    5)       The user wants to enter input company-code='1000' and write the data in a CSV file in a specific directory. i.e, by clicking the execute button (after entering company code) , the result should go to the CSV or text file. i.e. the application should automatically generate the file with query results.
    Note: The user should not use context menu to EXPORT TO CSV OR EXCEL file.
    Please let me know, if there is any tutorial. Thanks a lot advance help.
    Regards
    Kandasamy

    1. SELECT INTO
    Below method will create table when data is inserted from one table to another table. Its useful when you need exactly same datatype as source table.
    Use AdventureWorks2008R2;
    Go
    ---Insert data using SELECT INTO
    SELECT AddressLine1, City
    INTO BothellAddresses
    FROM Person.Address
    where City = 'Bothell';
    GO
    ---VERIFY DATA
    Select AddressLine1, City
    FROM BothellAddresses
    ---DROP TABLE
    DROP TABLE BothellAddresses
    GO
    2. INSERT INTO SELECT
    Below method will need table to be created prior to inserting data. Its really useful when table is already created and you want insert data from
    another table.
    Use AdventureWorks2008R2;
    Go
    ---Create Table
    CREATE TABLE BothellAddresses (AddressLine1 NVARCHAR(60), City NVARCHAR(30))
    ---Insert into above table using SELECT
    INSERT INTO BothellAddresses(AddressLine1, City)
    SELECT AddressLine1, City
    FROM Person.Address
    where City = 'Bothell';
    ---VERIFY DATA
    Select AddressLine1, City
    FROM BothellAddresses
    ---DROP TABLE
    DROP TABLE BothellAddresses
    GO
    Regards,
    Vishal Patel
    Blog: http://vspatel.co.uk
    Site: http://lehrity.com

  • How to get ODI execution results into ESS log file

    Hi,
    In out project, we are launching ODI scenario from ESS. Once, we launch the scenarion from ESS, we did not know whether the scenario got executed successfully or not. Is there any way to get the ODI execution result (i.e,. Failure message or success message which we can able to see in Operator window of ODI) into ESS log file.
    Thanks,
    Ganesh

    Hi
    As per your query, You need see log file for failure execution and for successful execution, you can also use odisendmail option, below is and example, it may helps you
    Please arrange below 3 in pkg
    1) OdiSqlUnload
    2) OdiSendmail ( Odisendmail1 and Odisendemail2 )
    3) create an excel file in your local machine (eg: in D: drive Error_log_Report )
    Flow in Pkg:
    Interface --->OK ----> Odisendmail1
    |__>KO ---->OdiSqlUnload ---> OK ----> Odisendmail2
    Please enter below details in SqlUnload properties
    Target File: Provide Error_log_Report.xls file location (Eg: D:\Error_log_Report.xls)
    JDBC Driver: Provide Target DB Drivers
    JDBC URL: Provide Target DB JDBC URL
    User: Provide Target DB username
    Password: provide target DB password
    SQL Query: write select query of SELECT FROM targetDB_Schema.E$_table_name (write select query for E$ table)
    Note: In OdiSendmail2, attached above .xls file for interface execution failure as error report
    Regards,
    Phanikanth

  • Exporting query results into a csv file using arabic and hebrew chars

    Hi,
    iv'e encountered a problem, using plsql to export a query into a csv file.. the arabic turns into question mark. Do you have any idea why?

    Usually this indicates a mismatch between client and database character set.
    How do you export this query?
    What is your database version?
    What is your client OS?
    T.

  • How to Save SQL query template as a text file

    Hi,
    How to save a SQL query template in my server as a Text file?? I tried using Text saver but it is not getting saved in the path specified.
    Sweety

    Hi Sweety,
    In the transaction editor (for business logic), add your query template to a transaction.  Add a Tracer after and link the Query property of the SQL Query action block to the Message property of the transaction.  Run the transaction and you will see your Action Block's sql script as the message from the Tracer.  You can do the same with the Server property, SD and ED, etc.
    Also if you wish to dynamically load the sql script into the query, you can do that at run time by linking a script source to the query property.  Useful to have if you have to use a complex expression to dynamically create your script.  This sometimes occurs when you have multiple filtering inputs from a webpage and you can reduce the number of tables in a complex join when the fields are left empty.  Normally this would be done as a way to improve the performance of the query.
    Hopefully this is clear.  If not I can probably provide some sample expressions.
    Regards,
    Mike

  • Show Select query result in the text file.

    Hi all,
    i want to show my select statment records in the text file.
    thanks in advance.
    Mob.

    you cannot do a select in a stored procedure.
    you could do something like
    SQL> set serverout on
    SQL> spool output.txt
    SQL> declare
           x varchar2(40);
         begin
           select * into x from dual;
           dbms_output.put_line(x);
         end;
    X
    SQL> spool offor use the utl_file package (more powerfull, less secure, write on the db-server instead of the sqlplus-client)

  • Oracle query export into the Excel file

    Hi,
    How can i automatically export oracle query result into the excel file in oracle?

    SQL and PL/SQL FAQ
    Re: Excel query to Oracle Database
    http://blog.mclaughlinsoftware.com/microsoft-excel/how-to-query-oracle-from-excel-2007/
    Edited by: swapnil kambli on May 28, 2013 11:07 PM

  • Download Internal Table into a Text File in BSP?

    I have an internal table which i need to download into my local pc. I know i can not use FM gui_download. Could some one please post code on how to download the internal table into a text file in BSP. Also i am not sure if i can use save dialog FM. Also need suggestion on which FM to use for save dialog which tells where to save the file.
    Any help will be appreciated.
    Thanks
    Nahman

    This might be a good starting point.
    <a href="/people/thomas.jung3/blog/2004/09/02/creating-a-bsp-extension-for-downloading-a-table">/people/thomas.jung3/blog/2004/09/02/creating-a-bsp-extension-for-downloading-a-table</a>

  • How To Re-Input More Data To A Text File?

    I was wondering if anyone could tell me how to re-input more data into a text file? I don't want to over-write the text file, but just add more data to it. The current code i have is:
    import java.util.Scanner;
    import java.io.*;
    class trialanderror002 {     
    public static void main(String args[]){     
         Scanner input = new Scanner(System.in);
         String str;
    FileOutputStream out;
    PrintStream p;
    try{
         out = new FileOutputStream("c:\\products.txt");
         p = new PrintStream(out);
         System.out.println("Please insert text to be written to file...");
         str = input.next();
         p.println (str);
         p.close();
    catch (Exception e){
         System.err.println ("Error writing to file");
    Basically, after each time the program is ran, i'd like to insert another line of data into products.txt.
    Is there a way for me to loop the program too and not remove the data from the text file?
    thanx...

    just one more question...
    i've figured out the code to retrieve the text file and print it to screen...but how do i go about only printing parts of my text file?
    So supposing my text file has 5 lines of data/text etc, how would i make it print the first line?...or the second line?...or the third....etc etc...
    the current code i now have is:
    package Assignment1;
    import java.util.Scanner;
    import java.io.*;
    class trialanderror002 {     
    public static void main(String args[]){     
         Scanner input = new Scanner(System.in);
         String str;
    FileOutputStream out;
    PrintStream p;
    try{
         out = new FileOutputStream("c:\\trial.txt", true);
         p = new PrintStream(out);
         System.out.println("Please insert text to be written to file...");
         str = input.next();
         p.println (str);
         p.close();
    catch (Exception e){
         System.err.println ("Error writing to file");
              try {
              FileReader file = new
              FileReader("c:\\trial.txt");
              BufferedReader buff = new
              BufferedReader(file);
              boolean eof = false;
              while (!eof){
                   String line = buff.readLine();
                   if (line == null)
                        eof = true;
                   else
                        System.out.println(line);
              buff.close();
              }catch (IOException e){
                   System.out.println("Error -- " + e.toString());
    }

  • How to insert the select query result into table?

    How to insert the select query result into table?
    SELECT  top 20 creation_time  
            ,last_execution_time 
            ,total_physical_reads
            ,total_logical_reads  
            ,total_logical_writes
            , execution_count 
            , total_worker_time
            , total_elapsed_time 
            , total_elapsed_time / execution_count avg_elapsed_time
            ,SUBSTRING(st.text, (qs.statement_start_offset/2) + 1,
             ((CASE statement_end_offset 
              WHEN -1 THEN DATALENGTH(st.text)
              ELSE qs.statement_end_offset END 
                - qs.statement_start_offset)/2) + 1) AS statement_text
    FROM sys.dm_exec_query_stats AS qs
    CROSS APPLY sys.dm_exec_sql_text(qs.sql_handle) st
    ORDER BY total_elapsed_time / execution_count DESC;
    Thanks,
    Tirumala

    1. SELECT INTO
    Below method will create table when data is inserted from one table to another table. Its useful when you need exactly same datatype as source table.
    Use AdventureWorks2008R2;
    Go
    ---Insert data using SELECT INTO
    SELECT AddressLine1, City
    INTO BothellAddresses
    FROM Person.Address
    where City = 'Bothell';
    GO
    ---VERIFY DATA
    Select AddressLine1, City
    FROM BothellAddresses
    ---DROP TABLE
    DROP TABLE BothellAddresses
    GO
    2. INSERT INTO SELECT
    Below method will need table to be created prior to inserting data. Its really useful when table is already created and you want insert data from
    another table.
    Use AdventureWorks2008R2;
    Go
    ---Create Table
    CREATE TABLE BothellAddresses (AddressLine1 NVARCHAR(60), City NVARCHAR(30))
    ---Insert into above table using SELECT
    INSERT INTO BothellAddresses(AddressLine1, City)
    SELECT AddressLine1, City
    FROM Person.Address
    where City = 'Bothell';
    ---VERIFY DATA
    Select AddressLine1, City
    FROM BothellAddresses
    ---DROP TABLE
    DROP TABLE BothellAddresses
    GO
    Regards,
    Vishal Patel
    Blog: http://vspatel.co.uk
    Site: http://lehrity.com

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

  • Query Output Into a Text File

    Hello Experts,
    There is a situation where i need ur help.My query is :
    Can I export the output of more than one queries into a * Single Text File * ?
    Also can it be possible to automate these Queries Output to export into the Text File ??
    I also want this Text File Output to mail the end users by using the Process Chain. So is this possible to create a process chain for sending this Text File to the Users via mail ??
    Thanks In Advance
    Neha

    Hello Neha,
    Though i have been working with APDs since some time. But havent actually been involved in designing one. But you could find many documents for the APD on web. And as far as i know, you will need a program to save file from APD.
    I have a document which explains how you can use APD in  process chain. can forward you the same if you want.
    I am sorry as i wasnt of much help for you, as i havent worked on similar requirement before, but this thing just striked in my mind.
    Regards,
    Anuj

Maybe you are looking for

  • Re-Write the Node-DOM code with SQL-XML funtions

    Hi Friends, Could you please help in re-writing the below code using SQl-XML functions DECLARE l_domdoc dbms_xmldom.DOMDocument; l_xmltype XMLTYPE; l_root_node dbms_xmldom.DOMNode; l_departments_node dbms_xmldom.DOMNode; l_dept_element dbms_xmldom.DO

  • Passbook causing iphone to restart each time I slide to view banner alert

    Trying to figure out if it's the application that is causing the crash or new 5S or both. Downloaded AMEX app and added a pass book scan through the app for one of my cards. Every time I use it the pass book displays a banner alert and it says " Slid

  • My incoming emailes default to plain text even though view-message body as-originalHTML is checked

    Most (not all) of my incoming emails (in particular from one main client's employees) always come in plain text, I want to be able to view all message in HTML format and reply in html format (this is generally fine fr my response, but the trail leave

  • Release Strategy for Contract

    Hello Experts     I am using release starategy for contract and using communication structure CEKKO in characteristics. I want to use other parameter such as material master number (MATNR) for characteristics. I see that CEKKO has component .INCLUDE

  • EXR and RPF rules for alpha and color management?

    How can I change the interpretation rules so that EXRs always import with straight alphas? They always import with Premulti now. Also, I want to always turn off color management (Preserve RGB) for RPFs. (I use RPFs for my motion vector passes and col