Sql query o/p into text file using 11g

i am using 11g. i want to write the result of the query into text file.how to do it

Hi if you are using SQL*plus then try with SPOOL command or if your are using TOAD then you can export the result of the query into a file of your choice. example Excel cheet or text file.
just right click on the result in your toad window and there will be a option of export result to a file.

Similar Messages

  • Spool SQl data into text file using dynamic sql

    Hi,
    I am spooling output data into text file using command
    select 'select t.mxname,bo.lxtype,t.mxrev'||chr(10)||'from mx_1234567'||chr(10)||
    'where <condition>';
    here mxname varchar(128),lxtype(128),mxrev(128) all are of varchar type.I want the output in format
    e.g Part|1211121313|A
    but due to column width the output,I am getting is with spaces.
    "Part then blank spaces |1211121313 then blank spaces |A"
    how can I remove these spaces between columns.I used set space 0 but not working.
    Thanks in advance.
    Your help will be appreciated.

    Hi Frank,
    I have seen your reply for SET LINE SIZE function. But, I could not be able to understand it.
    I am facing similar kind of issue in my present project.
    I am trying spool more than 50 columns from a table into flat file. Because of more column lengths in few columns, i am getting space. There are so many columns with the same issue. I want to remove that space.so that, data can fit perfectly in one line in .txt file without any wrap text.
    Below is my sample query.sql. Please let me know the syntax. My mail id : [email protected]
    --Created : Sep 22,2008, Created By : Srinivasa Bojja
    --Export all Fulfillments
    --Scheduled daily after 1:00am and should complete before 3:30am
    WHENEVER SQLERROR EXIT SQL.SQLCODE
    SET LINESIZE 800
    SET WRAP OFF
    SET PAGESIZE 800
    SET FEEDBACK OFF
    SET HEADING ON
    SET ECHO OFF
    SET CONCAT OFF
    SET COLSEP '|'
    SET UNDERLINE OFF
    SPOOL C:\Fulfillment.txt;
    SELECT SRV.COMM_METHOD_CD AS Method,
    SRV.SR_NUM AS "Fulfillment Row_Id",
    CON.LAST_NAME AS "Filled By"
    SRV.SR_TITLE AS Notes,
    SRVXM.ATTRIB_04 AS "Form Description"
    FROM SIEBEL.S_SRV_REQ SRV,
    SIEBEL.S_SRV_REQ_XM SRVXM,
    SIEBEL.S_USER USR,
    SIEBEL.S_CONTACT CON
    WHERE SRV.ROW_ID = SRVXM.PAR_ROW_ID AND
    SRV.OWNER_EMP_ID = USR.ROW_ID AND
    CON.ROW_ID= SRV.CST_CON_ID;
    SPOOL OFF;
    EXIT;

  • 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

  • Exporting query result set into CSV file using Forms

    Hi ,
    My requirement is
    -> I need to create a form where I have a Multi line text box and two button.
    -> When I enter a query in text box and click on Execute button, It should execute a select query.
    -> After execution, Result set needs to be exported into an Excel file.
    Please give a hint how to do this????
    Thanks,
    maddy

    as you are using text item to write SQL query by the user
    so for that you need to use the exec_sql package to parse the text items query and get definitions and values of the columns being
    resulted in the result set of the query.
    once your query is execute to the desired connection then you need to use fetch the result to the CSV file by use of the TEXT_io package
    which will open the text file with .csv extension and you have to pass the each line to that text file with comma separated values as "ss","rr" etc.
    or you can use the ole2 package to call the excel application and then fetch the data of exe_sql query to that.

  • How to display the out put of the sql query in a text file using forms

    I want to display the out put of the sql query in a text file using forms 6.0.Same could be done using spool command in sqlplus but i want it using forms....Fiaz

    Have a look at the text_io package:
    http://www.oracle.com/webapps/online-help/forms/10g/state?navSetId=_&navId=3&vtTopicFile=f1_help/oraini/c_text_io.html&vtTopicId=
    cheers

  • Generating text file using PL/SQL

    can any body send sample program how to generate text file using PL/SQL program.I want to store table data into that text file.

    Hi,
    try this.
    Thanks
    CREATE OR REPLACE procedure write_index (TABLE_NAME_ACCEPT VARCHAR2) IS
    id UTL_FILE.FILE_TYPE;
    name VARCHAR2(20) := 'e:\db_coca\input';      
    err VARCHAR2(100);      
    ColNameLength Integer;
    NumberoFColumns Integer;
    num NUMBER;           
    i integer;
    loc_query VARCHAR2(2000);
    cursor_name INTEGER;
    ret INTEGER;
    l_const_name VARCHAR2(30);
    CURSOR c_columns(i_Constraint_name VARCHAR2) IS
         SELECT *
         FROM     all_cons_columns
         WHERE     CONSTRAINT_NAME = i_Constraint_name
         order by table_name;
    BEGIN
    DBMS_OUTPUT.PUT_LINE('BEFORe OPEN');
    --id := UTL_FILE.FOPEN('e:\db_coca\input',name,'w');          
         --IF UTL_FILE.IS_OPEN(id) THEN
         --     DBMS_OUTPUT.PUT_LINE('Opened');
         --ELSE
         --     DBMS_OUTPUT.PUT_LINE('Still Closed');           
         --END IF;          
    DBMS_OUTPUT.PUT_LINE('AFTER OPEN');
    --The table generation script
         loc_query := 'Select CONSTRAINT_NAME from user_constraints ';
         loc_query := loc_query || ' where owner = ' || '''CPS''';
         loc_query := loc_query || ' AND CONSTRAINT_TYPE = ' || '''P''';
         dbms_output.put_line('TABLE_NAME_ACCEPT = ' || TABLE_NAME_ACCEPT);
         IF NOT (TABLE_NAME_ACCEPT IS NULL ) THEN
              loc_query := loc_query || ' AND TABLE_NAME like ''';
              loc_query := loc_query || TABLE_NAME_ACCEPT ;
              loc_query := loc_query || '''';
         END IF;
         cursor_name := DBMS_SQL.OPEN_CURSOR;
    dbms_output.put_line('Query = ' || loc_query);
         DBMS_SQL.PARSE(cursor_name, loc_query, DBMS_SQL.v7);
    dbms_output.put_line('After parse');
         dbms_sql.DEFINE_COLUMN(cursor_name, 1,l_const_name, 30);
         ret := DBMS_SQL.EXECUTE(cursor_name);
    --     IF ret > 0 THEN
         LOOP
         dbms_output.put_line('return = ' || ret);
              IF DBMS_SQL.FETCH_ROWS(cursor_name) > 0 THEN
                   dbms_sql.COLUMN_VALUE(cursor_name, 1,l_const_name);
              --     dbms_sql.BIND_VARIABLE(cursor_name,
    l_const_name,CONSTRAINT_NAME);
              --     FOR C10 in Table_Loop Loop          --The cursor
    for the table name
                   Select COunt(*) INTO NumberoFColumns from
                   all_cons_columns
                   Where CONSTRAINT_NAME = l_const_name;
         --          FOR C11 IN c_columns(l_const_name) LOOP
         --          End loop;
         --          UTL_FILE.PUT(id, ');');
              ELSE EXIT;
              END if;     --THe 1 st cursor if is closed
         End Loop;     --The table loop ends here
              DBMS_SQL.CLOSE_CURSOR(cursor_name);
    --     END IF;     
    --     UTL_FILE.PUT_LINE(id,name);
    --     UTL_FILE.PUT(id,'It worked and wrote to this file');
         UTL_FILE.FCLOSE(id);
         DBMS_OUTPUT.PUT_LINE('Successful write to file');          
    EXCEPTION     
    WHEN OTHERS THEN               
         err := SQLERRM;          
         num := SQLCODE;
         DBMS_OUTPUT.PUT_LINE(err);          
         DBMS_OUTPUT.PUT_LINE(num);
         DBMS_OUTPUT.PUT_LINE('Error in writing to file');     
    END write_index;

  • How to load decimal values into a file using bcp in SQL Server 2000?

    Hi everyone,
    I'm trying to load data from a database table to a text file using bcp on SQL Server 2000. When I'm loading the decimal values, the values before the decimal are not being loaded into the file. How could I load the values before decimals?
    Here are the DDLs and DMLs of what I'm trying to run:
    CREATE TABLE [dbo].[Product_Sales](
    [Year_of_Sale] [smallint] NOT NULL,
    [Product_Type] [varchar](25) NOT NULL,
    [Product_Group] [varchar](25) NOT NULL,
    [Category_Type] [varchar](25) NOT NULL,
    [Category_Group] [varchar](10) NOT NULL,
    [Product_Count] [bigint] NOT NULL,
    [Product_Amount] [decimal](19, 2) NOT NULL,
    [Category_Count] [bigint] NOT NULL,
    [Category_Amount] [decimal](19, 2) NOT NULL,
    CONSTRAINT [PK_Product_Sales] PRIMARY KEY CLUSTERED
    [Year_of_Sale] ASC,
    [Product_Type] ASC,
    [Product_Group] ASC,
    [Category_Type] ASC,
    [Category_Group] ASC
    ) ON [PRIMARY]
    ) ON [PRIMARY]
    INSERT INTO [Yearly_Sales].[dbo].[Product_Sales]
    VALUES(2010, 'Online', 'Web', 'Cameras', 'Electronics', 547, 0.00, 0, 0.00)
    EXEC [master].[dbo].[xp_cmdshell] 'bcp "SELECT * FROM [Yearly_Sales].[dbo].[Product_Sales]" queryout D:\Yearly_Sales\Product_Sales.dat -c -T -S'
    And the output I see in the file is:
    2010 Online Web Cameras Electronics 547 .00 0 .00
    The values before decimals are being truncated.
    Thanks,
    Bangaaram
    Known is a DROP, Unknown is an OCEAN.

    You can modify the decimal column(s) in the table to varchar type before export. But it does not look good.
    alter table [dbo].[Product_Sales]
    Alter column [Product_Amount] varchar(20)
    alter table [dbo].[Product_Sales]
    Alter column [Category_Amount] varchar(20)
    Does that make any sense?
    Known is a DROP, Unknown is an OCEAN.
    Basically you modify the decimal column to a varchar type before you run the bcp command for export. You can modify your source table or you can modify them on the fly. It is just a workaround.
    Modifying the source wouldn't be a good idea. Never do that if you can't get your desired output.
    Known is a DROP, Unknown is an OCEAN.

  • How to convert a HTML files into a text file using Java

    Hi guys...!
    I was wondering if there is a way to convert a HTML file into a text file using java programing language. Likewise I would also like to know if there is a way to convert any type of file (excel, power point, and word) into text using java.
    By the way, I really appreciated the help that you guys gave me on my previous topic on how to extract tests from a pdf file.
    Thank you....

    HTML files are already text files. What do you mean you want to convert them?
    I think if you search the web, you can find things for converting those MS Office files to text (or extracting text from them, as I assume you mean).

  • Uploading into database table from text file using tab (GUI_UPLOAD)

    i have small doubt
    i have 3 fiels in text file using tab as separator
    i need to update into database table 'ZABPSP_01'
    from 's.txt' located in local disk.
    My code is below.
    Please let me know the correction.
    Awaiting for ur response.
    Thanks in advance
    REPORT  ZABPSPPRG_02.
    TABLES: LFA1,MARA,KNA1,ZABPSP_01.
    DATA:  begin of itab occurs 0,
    IKUNNR type zabpsp_01-kunnr,
    IMATNR type zabpsp_01-matnr,
    IADRNR type zabpsp_01-adrnr.
    DATA:END OF ITAB.
    DATA: FILENAME1 TYPE STRING.
    FILENAME1 = 'C:/s.txt'.
    CALL FUNCTION 'GUI_UPLOAD'
      EXPORTING
        FILENAME                      = FILENAME1
      FILETYPE                      = 'ASC'
       HAS_FIELD_SEPARATOR           = 'X'
      HEADER_LENGTH                 = 0
      READ_BY_LINE                  = 'X'
      DAT_MODE                      = ' '
      CODEPAGE                      = ' '
      IGNORE_CERR                   = ABAP_TRUE
      REPLACEMENT                   = '#'
      CHECK_BOM                     = ' '
      VIRUS_SCAN_PROFILE            =
      NO_AUTH_CHECK                 = ' '
    IMPORTING
      FILELENGTH                    =
      HEADER                        =
      TABLES
        DATA_TAB                     = itab.
    EXCEPTIONS
      FILE_OPEN_ERROR               = 1
      FILE_READ_ERROR               = 2
      NO_BATCH                      = 3
      GUI_REFUSE_FILETRANSFER       = 4
      INVALID_TYPE                  = 5
      NO_AUTHORITY                  = 6
      UNKNOWN_ERROR                 = 7
      BAD_DATA_FORMAT               = 8
      HEADER_NOT_ALLOWED            = 9
      SEPARATOR_NOT_ALLOWED         = 10
      HEADER_TOO_LONG               = 11
      UNKNOWN_DP_ERROR              = 12
      ACCESS_DENIED                 = 13
      DP_OUT_OF_MEMORY              = 14
      DISK_FULL                     = 15
      DP_TIMEOUT                    = 16
      OTHERS                        = 17
    IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    IF sy-subrc EQ 0.
    zabpsp_01-kunnr = ITAB-IKUNNR.
    zabpsp_01-matnr = ITAB-IMATNR.
    zabpsp_01-adrnr = ITAB-IADRNR.
    WRITE : / ' UPLOAD SUCCESS ' .
    ENDIF.
    \[subject changed, don't write everything in upper case!\]
    Edited by: Jan Stallkamp on Aug 6, 2008 2:39 PM

    Hi,
    After upload modify the code like below. Also change the file name as some one suggested already. If u are still facing problems then check in debug mode what is happening after FM call.
    CALL GUI_UPLOAD FM.
    IF sy-subrc EQ 0
    IF NOT itab[] IS INITIAL.
    MODIFY ZABPSP_01 FROM TABLE itab.
    WRITE : / ' UPLOAD SUCCESS ' .
    ELSE.
    WRITE 'No data in file'.
    ENDIF.
    ELSE.
    WRITE 'Upload failure'.
    ENDIF.
    Thanks,
    Vinod.

  • Export batch data into CSV file using SQL SP

    Hi,
    I have created WCF-Custom receive adapter to poll Sql SP (WITH xmlnamespaces(DEFAULT 'Namespace' and For XML PATH(''), Type) . Get the result properly in batch while polling and but getting error while converting into CSV by using map.
    Please can anyone give me some idea to export SQL data into CSV file using SP.

    How are you doing this.
    You would have got XML representation for the XML batch received from SQL
    You should have a flat-file schema representing the CSV file which you want to send.
    Map the received XML representation of data from SQL to flat-file schema
    have custom pipeline with flat-file assembler on the assembler stage of the send pipeline.
    In the send port use the map which convert received XML from SQL to flat file schema and use the above custom flat-file disassembler send port
    If this answers your question please mark it accordingly. If this post is helpful, please vote as helpful by clicking the upward arrow mark next to my reply.

  • Creating a text file using pl/sql

    how can one create a text file using pl/sql?
    Say for example abcd.txt in the d: drive
    (d:\abcd.txt)
    on a windows nt server

    <BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by bhrigu nagal ([email protected]):
    thanks for your replies
    I had already set the utl_file_dir parameter
    I tried the utl package and wrote the following code but got some errors
    declare
    filehandler UTL_FILE.FILE_TYPE;
    begin
    filehandler:=UTL_FILE.fopen('d:/intel/','myfile.txt','w');
    utl_file.put_line(filehandler,'look masjdfgsd\n');
    utl_file.fclose(filehandler);
    exception when utl_file.invalid_path then
    raise_application_error(-20023,'bhrigu ,chk the path');
    end;
    the errors
    ERROR at line 1:
    ORA-06510: PL/SQL: unhandled user-defined exception
    ORA-06512: at "SYS.UTL_FILE", line 101
    ORA-06512: at "SYS.UTL_FILE", line 157
    ORA-06512: at line 4
    if u know what this is please tell me
    thanks bhrigu
    <HR></BLOCKQUOTE>
    U need :
    1) To have UTL_FILE_DIR param in the init file of the instance with the same directory (don't forget to stop and restart the base)
    2) Handled the exceptions listed in the utl_file package (Oracle_home\rdbms\admin\utlfile.sql) in your source.
    3) Turn set serveroutput on in SQL*Plus.
    Run your procedure and see the error message to debug.
    Good luck
    null

  • Compress Text File Using PL/Sql

    Hi All,
    My Environment is -------> Oracle 11g Database Release 1 On Windows 2003 Server SP2
    Requirement is ------------> Compress a text file using Oracle pl/sql
    I am tryring to compress a text file using below pl/sql code,
    DECLARE
    src_file BFILE;
    v_content BLOB;
    v_blob_len INTEGER;
    v_file UTL_FILE.file_type;
    v_buffer RAW(32767);
    v_amount BINARY_INTEGER := 32767;
    v_pos INTEGER := 1;
    v_blob BLOB;
    BEGIN
    src_file := BFILENAME('MY_FILES','expLive.log');
    DBMS_LOB.fileopen(src_file, dbms_lob.file_readonly);
    v_content := utl_compress.lz_compress(src_file);
    v_blob_len := DBMS_LOB.getlength(v_content);
    v_file := UTL_FILE.fopen('MY_FILES','test.log.zip','wb');
    WHILE v_pos < v_blob_len
    LOOP
    DBMS_LOB.READ(v_content, v_amount, v_pos, v_buffer);
    UTL_FILE.put_raw(v_file, v_buffer, TRUE);
    v_pos := v_pos + v_amount;
    END LOOP;
    UTL_FILE.fclose(v_file);
    EXCEPTION
    WHEN OTHERS THEN
    IF UTL_FILE.is_open(v_file) THEN
    UTL_FILE.fclose(v_file);
    END IF;
    RAISE;
    END;
    i am able to get the zip file without any problem.But the Problem here is size of the zip file, Acutal Text File Size is 520 KB and zip file size is 241KB. is there any possible way to compress little bit further to 100KB?
    Please Advice ....in case if you are have an example please share it.
    Thanks for your helps
    Shan

    is there any possible way to compress little bit furtherYou can compress better (but slower) with
    v_content := utl_compress.lz_compress(src_file, 9);
    ..

  • 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

  • Maintaining SQL Queries in a separate text file

    Hi,
    I am working on web based project using Spring MVC framework and I am maintaining all SQL queries in a separate text file so that I can change them any time when needed. I just want to know am I doing right, it this a optmistict way of coding??

    >
    I am working on web based project using Spring MVC framework and I am maintaining all SQL queries in a separate text file so that I can change them any time when needed. I just want to know am I doing right, it this a optmistict way of coding??
    >
    The best place to store the queries, and HOW to store them depends on your architecture and on how your application is being used.
    Is this a single-user application on a user's pc? Or is your application located on an application server in the middle-tier?
    The queries should be stored where they will be used. Your queries should be stored in the tier where your application code will reside. On the client PC for a single-user app, on the application server for a 3-tier app and incorporated into stored procedures/functions/packages if part of a database app.
    If your application is totally external to the database (e.g. a reporting app) then it doesn't make sense for you to become part of the database architecture. An org isn't going to let you create objects in the database to store your queries when your queries are not part of the database application. That puts the burden on them to backup your objects, restore them for your and provide support to you and your application.
    What format to store the queries in is a different issue. A major criteria is the type of queries you are using and how they are used. Many apps that query the database cannot just use hard-coded queries that are never modified. Users need to be able to provide parameters (e.g. name, ID, state, etc) to select just the data that they want.
    That means the base query itself may not even be valid syntax but needs to have a WHERE clause added. Prepared statements and queries that use bind variables ('WHERE ID = ?') are typically used for these.
    One method of storage is to use Java property files that use name=value pairs. Using property files makes it easy to use Java to find a query by name and load it for you. Then your code would have functionality to modify the query to provide the parameter 'bind' values and execute it.
    There are also frameworks available for handling database related functionality. There is no need for you to write your own libraries for this. I suggest you locate a suitable framework to use.

  • Downloading ...into text file

    hii Friends,,,,
                        i want to download report program into text file and its includes into seperate text file without using function modules.I want to do it with CL_GUI_FRONTEND_SERVICES and readreport.
    Kindly halp me or send any sample code???
    Regards Mandeep.

    Hi Mandeep Singh,
    The solution is simple press the button PATTERN or press CTRL + F6.
    That gives you a pop up.
    Select radio button "ABAP Object Patterns"
    Press Enter.
    In Call Method radio button.
    Type "CL_GUI_FRONTEND_SERVICES"  in Class/Interface.
    <b>Select the METHOD of your choice by pressing F4 in the box Method.</b>
    This should solve the query.
    Reward Points if useful.
    Thanks,
    Tej..

Maybe you are looking for

  • Matlab workspace not getting updated while labview mex file is running

    Hi, Let me start from the overview of the system for better understanding. The system is to acquire data from a DAQ6070e using labview 7.1 . this data is then to be used in matlab for processing. All this needs to happen in real time hence the data i

  • Do I need pages work with/save Office docs?

    I'm confused on how iCloud works with saving documents.  It mentions a number of times that you can work with Office documents, but then it says you need Pages on both my iPhone and Computer to be able to work with and save documents in icloud.    Ho

  • MDM key mapping: multiple fields?

    Hallo, is it possible to base key mapping on more than one fields? From what i see key mapping is based on one field only... Regards, Marco

  • Java heap won't shring

    java version "1.6.0_11" Java(TM) SE Runtime Environment (build 1.6.0_11-b03) Java HotSpot(TM) 64-Bit Server VM (build 11.0-b16, mixed mode) I have an application that sees bursts of activity and long periods of no work. Recently I checked and the mem

  • Can't Access Home page in another system

    Hi All, I had recently installed BO 3.1 and when i tried to access the CMC IP link (http://ct-c8-pc1:8080/CmcApp/logon.faces) from another system it throws an error "Cannot find page:CmcApp/logon.faces". I had open the ports for tomcat 8080 and CMS (