Spool file with comma including quotes

Hi All,
I am getting the csv file however location commas are treated as another column in file. I am expecting based on the below SQL only two columns and all the data should be in two columns though we have comma value in location string.
CREATE TABLE DEPT ( DEPTNO NUMBER,LOCATION VARCHAR2(255));
INSERT INTO DEPT (DEPTNO,LOCATION) VALUES(100, 'CHICAGO,NEWYORK');
INSERT INTO DEPT (DEPTNO,LOCATION) VALUES(200, 'ATLANTA,NEWYORK');
INSERT INTO DEPT (DEPTNO,LOCATION) VALUES(300'OMHA,NEWYORK');
INSERT INTO DEPT (DEPTNO,LOCATION) VALUES(100, 'NEWJERSEY,NEWYORK');
COMMIT;
sql file :
set pagesize 10000
set feedback off
set heading off
set echo off
spool r:\dept.csv
select to_char(deptno)||','||rtrim(location)
  from dept;
spool off
set echo on
set heading on
set feedback onEdited by: user1758353 on Dec 6, 2011 7:47 AM
Edited by: user1758353 on Dec 6, 2011 7:47 AM
Edited by: user1758353 on Dec 6, 2011 7:48 AM

try to wrap your column location with a double quotes.
e.g.
select to_char(deptno)||','||'"'||rtrim(location)||'"'
  from dept;when you opened your csv file on excel it considers the strings enclosed on a double quotes as one column.

Similar Messages

  • Unable to Load CSV file with comma inside the column(Sql Server 2008)

    Hi,
    I am not able load an CSV file with Comma inside a column. 
    Here is sample File:(First row contain the column names)
    _id,qp,c
    "1","[ ""0"", ""0"", ""0"" ]","helloworld"
    "1","[ ""0"", ""0"", ""0"" ]","helloworld"
    When i specify the Text Qualifier as "(Double quotes) it work in SQL Server 2012, where as fail in the SQL Server 2008, complaining with error:
    TITLE: Microsoft Visual Studio
    The preview sample contains embedded text qualifiers ("). The flat file parser does not support embedding text qualifiers in data. Parsing columns that contain data with text qualifiers will fail at run time.
    BUTTONS:
    OK
    I need to do this in sql server 2008 R2 with Service pack 2, my build version is 10.50.1600.1.
    Can someone let me know it is possible in do the same way it is handle in SQL Server 2012?
    Or
    It got resolved in any successive Cumulative update after 10.50.1600.1?
    Regards Harsh

    Hello,
    If you have CSV with double quotes inside double quotes and with SSIS 2008, I suggest:
    in your data flow you use a script transformation component as Source, then define the ouput columns id signed int, Gp unicode string and C unicode string. e.g. Ouput 0 output colmuns
    Id - four-byte signed
    gp - unicode string
    cc - unicode string
    Do not use a flat file connection, but use a user variable in which you store the name of the flat file (this could be inside a for each file loop).
    The user variable is supplied as a a readonly variable argument to the script component in your dataflow.
    In the script component inMain.CreateNewOutputRows use a System.IO.Streamreader with the user variable name to read the file and use the outputbuffer addrow method to add each line to the output of the script component.
    Between the ReadLine instraction and the addrow instruction you have to add your code to extract the 3 column values.
    public override void CreateNewOutputRows()
    Add rows by calling the AddRow method on the member variable named "<Output Name>Buffer".
    For example, call MyOutputBuffer.AddRow() if your output was named "MyOutput".
    string line;
    System.IO.StreamReader file = new System.IO.StreamReader( Variables.CsvFilename);
    while ((line = file.ReadLine()) != null)
    System.Windows.Forms.MessageBox.Show(line);
    if (line.StartsWith("_id,qp,c") != true) //skip header line
    Output0Buffer.AddRow();
    string[] mydata = Yourlineconversionher(line);
    Output0Buffer.Id = Convert.ToInt32(mydata[0]);
    Output0Buffer.gp = mydata[1];
    Output0Buffer.cc = mydata[2];
    file.Close();
    Jan D'Hondt - SQL server BI development

  • Spool file with sysdate

    How create spool file with current date and time?
    I want to create spool file like xyz_28062010.
    Please, suggest.

    like:
    In SQL*Plus this is what you can do to get the current date/time as part of the spool file:
    ============================================================================================
    SQL> column tm new_value file_time noprint
    SQL> select to_char(sysdate, 'YYYYMMDD') tm from dual ;
    1 row selected.
    SQL> prompt &file_time
    20020816
    SQL> spool C:\Temp\logfile_id&file_time..log Reference: Creating a spool file with date/time appended to file name
    Edited by: Gj on Jun 28, 2010 11:45 AM

  • Creating a spool file with date/time appended to file name

    In Oracle Sql*Plus, I want to spool out a file, with the date-time stamp as part of the file name. Any idea how to do this?
    Here's what I have right now:
    SQL>
    set serveroutput on size 200000;
    rem
    rem $OFSA is a UNIX alias so sql plus is talking to UNIX
    rem
    spool $OFSA/logs/OFSAP/common_coa_id.log;
    prompt 'Enter date in mmddyyyy format, without quotes';
    exec upd_common_coa_id_driver ('&date_mmddyyyy');
    spool off;
    As an example, I'd like to have a file with this name: common_coa_id083002.log
    Thanks.

    In SQL*Plus this is what you can do to get the current date/time as part of the spool file:
    ============================================================================================
    SQL> column tm new_value file_time noprint
    SQL> select to_char(sysdate, 'YYYYMMDD') tm from dual ;
    1 row selected.
    SQL> prompt &file_time
    20020816
    SQL> spool C:\Temp\logfile_id&file_time..log
    . /* put your code here */
    . /* it will go to a file called C:\Temp\logfile_id20020816.log */
    SQL> spool off
    SQL>

  • Creation of Spool File with Triggers

    Hi,
    I have created an OnUpdate trigger using the Essbase Console. I am using a calculation script to change the value of an account that is being used in the trigger. The trigger doesnot craete a spool file. Can anyone help me with it.

    Are you sure that the data value that should change did change?
    Here I am plugging Glenn's presentation twice in like five minutes. Check out this (unrelated) thread -- it explains how to get to his Kaleidoscope presentation.
    How to use a substitution variable in a load rule?
    FWIW, this part of the presentation was really good (it was all good, but I particularly enjoyed this bit).
    Regards,
    Cameron Lackpour

  • Can you open CSV-files with commas?

    It seems to me that we have something of a regression in Numbers 2.0 (part of iWork '09) - it (like Excel before it) no longer opens regular CSV-files.
    When I use the new Numbers to try to make a CSV-file, it'll actually use semicolons instead of commas, and any of my old CSV-files (like this one: http://d.ooh.dk/misc/postnumre.csv ) (with commas) will load all the values (and the commas) in a single column.
    I wonder if it's just me, or perhaps only a problem when using European notation (with comma as the decimal separator)?

    At last, Apple adopted the same behavior than Bento 1.
    When the decimal separator is the period, it works with standard CSV files.
    When the decimal separator is comma, it works with CSV using the semi-colon as item delimiters.
    To open your old CSV, set temporarily your system to a region whose decimal separator is period. Given that, Numbers will open them flawlessly.
    The ability to chose the separator (as it is now in Bento 2) would have been fine .
    Yvan KOENIG (from FRANCE dimanche 11 janvier 2009 20:30:03)

  • Multiple flat files with Comma delimiter and Pipe Delimiter in the sub folders.

    Hi,
    I have a directory C:\doc\Outcomes\Health  --(This is the main path). 
    In the path above i have multiple subfolders like 
    A
    B
    C
    D
    Folder A & B have 20 flat files each which are comma separated and pipe delimiter files. 
    Folder C&D have 20 excel files each.
    1) So, In SSIS while looping through the subfolders how do i limit to loop only excel files one time and flat files one time.
    2) In folder A&B, how do i loop only Pipe delimiter files (neglecting comma saperated files). I want to loop only pipe delimiter files while using for each loop container.
    Thanks 

    Both are txt files, but the data inside the files is saperated by ',' and '|'. ( comma and pipe)
    Thats ok 
    If delimiters are not consistent you can use this method
    http://visakhm.blogspot.in/2014/07/ssis-tips-handling-inconsistent-text.html
    Please Mark This As Answer if it solved your issue
    Please Mark This As Helpful if it helps to solve your issue
    Visakh
    My MSDN Page
    My Personal Blog
    My Facebook Page

  • Spool file with just the data

    Hi,
    I have a sql query that I'm spooling to a file. I have set echo off, heading off, feedback off, verify off. The spool file is exactly what I want except for the SQL prompt and the actual query. It looks like this:
    SQL> "select statement;"
    data data
    data data
    data data
    data data
    SQL>
    What parameter do I set so that the
    SQL> "select statement"
    doesn't appear in the spooled file at the top, and
    SQL>
    doesn't appear at the bottom?
    I need data only.
    Thanks
    -Bob

    Hi,
    Try running your SQL from within a script instead of executing it directly from SQL prompt.
    i.e. Script a.sql
    set head off;
    set echo off;
    set feed off;
    set verify off;
    spool c:\1;
    select col1, col2
    from table;
    Spool Off;
    set head on;
    set echo on;
    set feed on;
    set verify on;
    In SQL promot,
    SQL> @a
    This should give you the output without SQL commands etc.
    Shailender Mehta

  • Websites which have files with filenames including an underscore do not display correctly.

    HTML files with Image files with an underscore in their name don't display the image files. They do display under Konqueror. Firefox displays the image files OK if you type their URL into the control bar. The URL below provides an example, and look e.g at the file. CEOHT_16months.jpg
    Thank you.

    No problems here with the images.
    Start Firefox in <u>[[Safe Mode]]</u> to check if one of the extensions or if hardware acceleration is causing the problem (switch to the DEFAULT theme: Firefox (Tools) > Add-ons > Appearance/Themes).
    *Don't make any changes on the Safe mode start window.
    *https://support.mozilla.com/kb/Safe+Mode
    See also:
    *http://kb.mozillazine.org/Images_or_animations_do_not_load

  • Spool to csv file problem--comma included in the data

    Friends,
    i spooled the table's data to csv file.
    when i open it in the excel sheet some of the records are in the different cells.
    below is the record....
    Colonial Street, Ruwanda
    so when i view it in the excel sheet.
    Colonial Street is coming in one cell
    and
    Ruwanda is coming in the next cell.
    but "Colonial Street, Ruwanda" is the single entry in the column.
    so how can i spool the record which is having comma (,) in between the words to get it in the single cell of excel?
    thanks

    Usually putting double quotes around your column values should take care of that:
    select     '"'||column1
           ||'","'||column2
           ||'","'||column3||'"'
    from   your_table

  • Pipe Delimited file with comma

    Hi Guys,
    I have a pipe '|' delimited csv file. One of the field contains ',' (comma) for few records. The data loads fine uptill the PSA but when I load the data in the cube, that field is coming empty as well as some other feilds which donot have a comma in it.
    The delmiter in IP and DS is used '|' pipe.

    A pipe within quotes? I don't think you can do that with regex. But you can simply itearate through the chars of the String with an "isInsideQuotes" boolean flag and do a manual replacement using StringBuffer.

  • Uploading file with comma separator

    Hi firends,
    I have a text file in the format below.
    "abc","dedffrt","asd"
    The value of field is enclosed in double quotes and each values are separated by comma.
    I have tried with the function modules available for upload but of no use.
    Im aware of the methods uploading and splitting ...
    But i want to know is there any other function modules available to upload the file of this type.
    Keshav

    Hi KSD,
    Try this way.
    REPORT ztest_notepad.
    DATA: BEGIN OF it_t001 OCCURS 0,
            bukrs TYPE t001-bukrs,
            butxt TYPE t001-butxt,
          END OF it_t001.
    DATA: BEGIN OF it_file OCCURS 0,
            data TYPE char255,
          END OF it_file.
    START-OF-SELECTION.
      CALL FUNCTION 'GUI_UPLOAD'
        EXPORTING
          filename = 'C:\hor_file.txt'
          filetype = 'ASC'
        TABLES
          data_tab = it_file.
      REPLACE ALL OCCURRENCES OF '"' IN TABLE it_file WITH space.
      LOOP AT it_file.
        SPLIT it_file-data AT ',' INTO it_t001-bukrs it_t001-butxt.
        APPEND it_t001.
        CLEAR it_t001.
      ENDLOOP.
      LOOP AT it_t001.
        WRITE:/ it_t001-bukrs, it_t001-butxt.
      ENDLOOP.
    <li>Text file
    "CGH","CGH Hospital"
    "KKH","KKH hospital"
    "SGH","SGH Hospital"
    Thanks
    Venkat.O

  • Download internal table as text file with comma separation

    hi all
    I wanted text file separated by comma. I used the CSV function module, but the result is separeted by semicolon,instead i need comma.
    Kindly suggest some solution.
    Thanks
    Subha

    use this fm to convert to csv file
    CALL FUNCTION 'SAP_CONVERT_TO_TEX_FORMAT'
        EXPORTING
          I_FIELD_SEPERATOR    = ','
        TABLES
          I_TAB_SAP_DATA       = ITAB_FINAL
        CHANGING
          I_TAB_CONVERTED_DATA = ITAB_OUTPUT
        EXCEPTIONS
          CONVERSION_FAILED    = 1
          OTHERS               = 2.
      IF SY-SUBRC <> 0.
    * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
    itab_output is of type ITAB_OUTPUT TYPE TRUXS_T_TEXT_DATA,
    and then download using gui_download
    CALL FUNCTION 'GUI_DOWNLOAD'
          EXPORTING
            FILENAME                = W_FILENAME
            FILETYPE                = 'ASC'
          TABLES
            DATA_TAB                = ITAB_OUTPUT
          EXCEPTIONS
            FILE_WRITE_ERROR        = 1
            NO_BATCH                = 2
            GUI_REFUSE_FILETRANSFER = 3
            INVALID_TYPE            = 4
            NO_AUTHORITY            = 5
            UNKNOWN_ERROR           = 6
            HEADER_NOT_ALLOWED      = 7
            SEPARATOR_NOT_ALLOWED   = 8
            FILESIZE_NOT_ALLOWED    = 9
            HEADER_TOO_LONG         = 10
            DP_ERROR_CREATE         = 11
            DP_ERROR_SEND           = 12
            DP_ERROR_WRITE          = 13
            UNKNOWN_DP_ERROR        = 14
            ACCESS_DENIED           = 15
            DP_OUT_OF_MEMORY        = 16
            DISK_FULL               = 17
            DP_TIMEOUT              = 18
            FILE_NOT_FOUND          = 19
            DATAPROVIDER_EXCEPTION  = 20
            CONTROL_FLUSH_ERROR     = 21
            OTHERS                  = 22.

  • Downloading into a text file with comma seperation

    hey experts,
    well i want to download various fields of an internal table into a text file.but the hitch is that all the columns should be seperated by a comma.something like csv.
    could you please help me with this.?
    i have tried using gui download but the seperator field was not working.
    thanks in advance...
    regards,
    sandra.

    hey sandra,
    for comma seperation and downloading ,you can use the following fm.
    here the i_field seperator should be given as "," as in ur case.
    i_tab3 is the table from which the values are being fetched.
    and i_tab2 is the table conatining the comma seperated values.
    CALL FUNCTION 'SAP_CONVERT_TO_TEX_FORMAT'
       EXPORTING
         I_FIELD_SEPERATOR          = ','
      I_LINE_HEADER              =
      I_FILENAME                 =
      I_APPL_KEEP                = ' '
       TABLES
         I_TAB_SAP_DATA             = I_TAB3
       CHANGING
        I_TAB_CONVERTED_DATA       = I_TAB2
    EXCEPTIONS
      CONVERSION_FAILED          = 1
      OTHERS                     = 2
      IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
    after this u can use the gui download fm as required.
    CALL FUNCTION 'GUI_DOWNLOAD'
    EXPORTING
      BIN_FILESIZE                    =
        FILENAME                        = TESTFILNA
      FILETYPE                        = 'ASC'
      APPEND                          = ' '
        WRITE_FIELD_SEPARATOR           = 'x'
      HEADER                          = '123'
      TRUNC_TRAILING_BLANKS           = ' '
      WRITE_LF                        = 'X'
      COL_SELECT                      = ' '
      COL_SELECT_MASK                 = ' '
      DAT_MODE                        = ' '
      CONFIRM_OVERWRITE               = ' '
      NO_AUTH_CHECK                   = ' '
      CODEPAGE                        = ' '
      IGNORE_CERR                     = ABAP_TRUE
      REPLACEMENT                     = '#'
      WRITE_BOM                       = ' '
      TRUNC_TRAILING_BLANKS_EOL       = 'X'
      WK1_N_FORMAT                    = ' '
      WK1_N_SIZE                      = ' '
      WK1_T_FORMAT                    = ' '
      WK1_T_SIZE                      = ' '
      WRITE_LF_AFTER_LAST_LINE        = ABAP_TRUE
    IMPORTING
      FILELENGTH                      =
    TABLES
          DATA_TAB                      = I_TAB2
      FIELDNAMES                      =
    EXCEPTIONS
      FILE_WRITE_ERROR                = 1
      NO_BATCH                        = 2
      GUI_REFUSE_FILETRANSFER         = 3
      INVALID_TYPE                    = 4
      NO_AUTHORITY                    = 5
      UNKNOWN_ERROR                   = 6
      HEADER_NOT_ALLOWED              = 7
      SEPARATOR_NOT_ALLOWED           = 8
      FILESIZE_NOT_ALLOWED            = 9
      HEADER_TOO_LONG                 = 10
      DP_ERROR_CREATE                 = 11
      DP_ERROR_SEND                   = 12
      DP_ERROR_WRITE                  = 13
      UNKNOWN_DP_ERROR                = 14
      ACCESS_DENIED                   = 15
      DP_OUT_OF_MEMORY                = 16
      DISK_FULL                       = 17
      DP_TIMEOUT                      = 18
      FILE_NOT_FOUND                  = 19
      DATAPROVIDER_EXCEPTION          = 20
      CONTROL_FLUSH_ERROR             = 21
      OTHERS                          = 22
      IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
    hope this helps u.
    do reward points if useful.....:-)

  • How to spool file with a timestamp/seq_number in the file name

    Hi I try to write a test script that will have some kind of timestamp or seq_number in the spool output file's filename itself.
    so e.g.
    test_abc_20120425161616.txt
    I can do it on shell but is there a way I can do it all in sqlplus.
    I recall I see something similar in statpack long time ago..

    vxwo0owxv wrote:
    Hi I try to write a test script that will have some kind of timestamp or seq_number in the spool output file's filename itself.
    so e.g.
    test_abc_20120425161616.txt
    I can do it on shell but is there a way I can do it all in sqlplus.
    I recall I see something similar in statpack long time ago..
    >Hi I try to write a test script that will have some kind of timestamp or seq_number in the spool output file's filename itself.
    so e.g.
    test_abc_20120425161616.txt
    I can do it on shell but is there a way I can do it all in sqlplus.
    I recall I see something similar in statpack long time ago..
    set termout off
    col dt new_value dt
    select to_char(sysdate,'YYYYMMDDHH24MISS') dt from dual;
    set termout on
    spool file_&dt
    -- place your SQL here
    spool off
    Handle:     vxwo0owxv
    Status Level:     Newbie
    Registered:     Mar 14, 2011
    Total Posts:     142
    Total Questions:     79 (59 unresolved)
    WHY am I NOT surprised?
    Edited by: sb92075 on Apr 24, 2012 4:37 PM

Maybe you are looking for

  • Qry:How to get different price for each price list (variable area) in order

    1-How to get different price for each price list (variable area) in order for sale. for the opportunity to display and select multiple prices. 2- I add a location store from a table in line item and I want to see this area in order,. I 'm created 2 f

  • PI 7.4 Single Stack - OS Command and Java Mapping Trace

    Hi, Since ABAP stack is not avilable how to use the OS command and also want to know how to check the trace for java mapping since sxmb_moni is not avilable. Please send me some link for 7.4 or 7.31 single stack document. Thanks Jignesh shah

  • How to declare global variables using another global variable in ODI

    I am declaring a gloabal variable using another global variable. say for example: I have a global variable empid. I am decalaring another global variable empname in refreshing tab of global variables and the select statment is select empname from emp

  • RSS Bookmarks in bookmarks bar not updating.

    Just recently I've noticed that my RSS feeds are not updating. Usually when there is a new article, a number appears next to the bookmark but that is not happening here. If I click on the bookmark, it shows all the new articles but there are no numbe

  • Adobe - Cannot Open Program/PDFs

    I cannot open my reader (11.0.03) or my Adobe X Pro.  I have Windows 7 and a number of other Adobe programs on the machine.  I have done what Adobe suggests about going to my control panel, highlighting the program and the change button.  Everything