Split String at delimiter into table.

Hi Experts,
I have a requirement wherein i need to split aaaa#bbbbbbbbbbbb#ccc#dddddddddddddddddddddd#e# into internal table as below:
Header 1
Header 2
1
aaaa
2
bbbbbbbbbbbb
3
ccc
4
dddddddddddddddddddddd
5
e
how can this be done.
Thanks & Regards,
Anil

Hi Ashok,
split <string> at '#' into table it.  -Doesn't work
split <string> at SPACE into table it. - Works
But same statement with '#' is not working.
Feeling strange.
Thanks,
Anil

Similar Messages

  • SPLIT data-record AT delimiter into table-fieldname

    Hi all,
    I have the following SPLIT statement. But unable to split into respective field in an internal table. I'm using the standard delimeter.
    Please help me how to create a file using the delimeter w_delimeter.
    When I create the file with separated by '#' even it is not spliting.
    w_delimeter TYPE c value cl_abap_char_utilities=>horizontal_tab.
    SPLIT data-record AT w_delimeter INTO i_0208-pernr
                                                                         i_0208-begda
                                                                        i_0208-endda
                                                                        i_0208-wtart
                                                                        i_p0208-allpc.
    Thanks,
    Prasad

    Hi Prasad,
    it should work try this bellow piece of code.
    REPORT  ZTEST_A.
    data: Begin of itab occurs 1,
            name(30),
            street(30),
            Apt(3),
            city(30),
            state(2),
            zipcode(5),
          end of itab,
          text1(250),
          text2(250).
    Text1 = 'Jacson  3 xyz dr  B4  abcd  DE  12345'.
    Text2 = 'Edward  3 Caaa dr  B4  pqr  DE  54623'.
    split text1  AT '  '  into   itab-name itab-street  itab-Apt
            itab-city itab-state itab-zipcode.
    append itab.
    split text2  AT '  '  into   itab-name itab-street  itab-Apt
            itab-city itab-state itab-zipcode.
    append itab.
    thanks,
    Venkat

  • How to split a string having string as delimiter instude of char?

    Hello Gurus,
    I want to split the string and work on each split string.
    The following code will do, but not exactly.
    It's split into morethan three strings, where coma find.
    But I want to split it using #,# as delimiter.
    Here is my code:
    //File fileData = new File("myfile.txt");
    // This will have coma separated fields data
    // while traversing this file will readLine() give the string, that is strRecord
    // BufferedReader bfrdRdrObj = new BufferedReader(new FileReader(strDataFile));
    //while ((strThisLine = bfrdRdrObj.readLine()) != null) {..........
    String strRecord = #A001#,#User1#,#this is record, so need to split and place, insert into table#;
    StringTokenizer strTknRec = new StringTokenizer(strRecord,"#,#");
    int iCounter=0;
    while(strTknRec.hasMoreTokens()){
    System.out.println(++iCoutner+"Field: "+strTknRec.nextToken());
    Please, give me hint.
    Thanks in advance.
    ~ SubbaReddy .M

    Hello Guru,
    Here "myfile.txt" CSV file.
    each line represented treated as a record and coma seperated string is treated as fields.
    But, one of the fields data may have the coma in the string itself. So, # or " (double quote) has been place before and end of the field data as a string qualifier.
    //File fileData = new File("myfile.txt");
    // This will have coma separated fields data
    // while traversing this file will readLine() give the string, that is strRecord
    // BufferedReader bfrdRdrObj = new BufferedReader(new FileReader(strDataFile));
    //while ((strThisLine = bfrdRdrObj.readLine()) != null) {..........
    String strRecord = #A001#,#User1#,#this is record, so need to split and place, insert into table#;
    StringTokenizer strTknRec = new StringTokenizer(strRecord,"#,#");
    int iCounter=0;
    while(strTknRec.hasMoreTokens()){
    System.out.println(++iCoutner+"Field: "+strTknRec.nextToken());
    And I would like to run this JRE 1.3.1
    Hope, String.split() in JRE 1.4.0 beta will some what resolve this.
    But, how to do it on JRE 1.3.1
    Please, give me hint.
    Thanks in advance.

  • Split string into itab

    Hello,
    I am trying to split a string into an internal table with:
    split content at '##' into table it_content
    but as the expected 6 line I only get 1 line into the table with the complete string.
    Any ideas?
    regards
    stefan

    Hi,
    You need to write the Program like below
    DAta: DEL(3) VALUE '***'.
    SPLIT content AT DEL INTO TABLE <itab>.
    The system adds a new line to the internal table <itab> for each part of the string.
    Regards
    Sudheer

  • Error in splitting records from an internal table

    Hi all,
        After uploading the data from flat file into an internal table the data consists of # between each field and while I try to split each field and assign to a different table the data is not getting split properly ,
    i.e. split function splits the fields after 3 '#' and storing it in the table field.
    Thanks & Regards
    Jerry

    Hi Jerry,
    What Uwe said is correct. We too faced that kind of scenario. In the internal table when uploaded from flat file it will show '#' but it wont get split with '#' symbol in the program. However we solved the issue with the following class.
    Data: c_tab value cl_abap_char_utilities=>newline,
             it_string type table of string.
    " if it_table1 is the table which contains the flat file data, then go throuhg  this logic.
    loop at it_table1 into wa_table1.
    split wa_table1 at c_tab into table it_string.
    endloop.
    If the table is not getting split with cl_abap_char_utilities=>newline, then try using differnt attributes of that class ( like cl_abap_char_utilities=>cr_lf, cl_abap_char_utilities=>backspace so on ).
    Hope this will help.
    Regards,
    Swarna Munukoti.
    Edited by: Swarna Munukoti on Sep 13, 2008 5:54 PM

  • Copying data from excel(more than one row) and pasting into table control

    I have a requirement to copy data from excel and have it pasted it into the corresponding fields table control when the user clicks on an icon.For the first part I used a class to copy it from the clip board.By the previous process,I get the data inside an internal table, but even after  trying to split the data using 'split at cl_abap_char_utilities=>horizontal_tab into table itab.' it's not working.The table and the excel file are of the same structure.
    Does anyone know any cause as to why it might not work?Is there any other way to achieve my objective?
    Bon

    Hi,
    try to get data into internal table as below
    TYPES :     BEGIN     OF             ty_data          ,
                zbukr     TYPE           payr-zbukr       ,
                hbkid     TYPE           payr-hbkid       ,
                hktid     TYPE           payr-hktid       ,
                rzawe     TYPE           payr-rzawe       ,
                chect     TYPE           payr-chect       ,
                laufd     TYPE           reguh-laufd      ,
                laufi     TYPE           reguh-laufi      ,
                lifnr     TYPE           reguh-lifnr      ,
                vblnr     TYPE           reguh-vblnr      ,
                rwbtr     TYPE           reguh-rwbtr      ,    "uncommented
                unique_no TYPE           char13           ,   " Added SAP Doc. No. and current year concate in NEFT,RTGS and Fund Transfer cases
                END       OF             ty_data          .
    DATA :      wa_file   LIKE LINE OF   it_file          ,
                wa_data   TYPE           ty_data          .
    DATA:      it_data1 TYPE              kcde_intern WITH HEADER LINE,
               wa_data1 LIKE LINE OF      it_data1.
    start-of-selection.
    CALL FUNCTION 'KCD_EXCEL_OLE_TO_INT_CONVERT'
          EXPORTING
            filename                = lv_file1
            i_begin_col             = '1'
            i_begin_row             = '4'
            i_end_col               = '11'
            i_end_row               = '60000'
          TABLES
            intern                  = it_data1
          EXCEPTIONS
            inconsistent_parameters = 1
            upload_ole              = 2
            OTHERS                  = 3.
        IF sy-subrc = 0.
          PERFORM format_data.
        ENDIF.
    FORM format_data.
      DATA : ld_index TYPE i.
      FIELD-SYMBOLS : <fs>.
      DATA it_tab LIKE wa_data OCCURS 0 WITH HEADER LINE.
          LOOP AT it_data1.
            MOVE it_data1-col TO ld_index.
            ASSIGN COMPONENT ld_index OF STRUCTURE
            it_tab TO <fs>.
            MOVE : it_data1-value TO <fs>.
        MOVE it_data1-value TO p_table.
            AT END OF row.
              APPEND it_tab.
              CLEAR it_tab.
            ENDAT.
          ENDLOOP.
           it_data[] = it_tab[] .
        ENDIF.
    endform.                    "format_data

  • Inserting the Comma Separated Strings into Table

    Hi Seniors,
    i had two string and i want to insert the records in the Table COMMENT . In this way.
    would u please give some programe to insert the records.
    The Data and the Table
    ( 901,902,903,904 )
    ( 'hai','nice','good & mail is [email protected] ','excellent and the phone 011-235323' )
    comm_id loc_id company_name comments
    1      10 901      Hai
    2      10 902      nice
    3 10      903      good & mail is [email protected]
    4      10 904      excellent and the phone 011-235323
    Thanks
    Seenu

    Hi, Seenu,
    In Oracle 10 (and up) you can easily split a comma-delimited list using REGEXP_SUBSTR.
    INSTR and SUBSTR can do the same thing in any version, but it's more complicated.
    See the general instructions below:
    /*     How to Split a Delimited String
    This shows how to take a single row with a delimited string, such as
         Animal     amoeba,bat,cedusa,dodo
    and transform it into multiple rows:
         Animal     1     amoeba
         Animal     2     bat
         Animal     3     cedusa
         Animal     4     dodo
    PROMPT     ==========  -1. sep_char parameter  ==========
    VARIABLE     sep_char     VARCHAR2 (10)
    EXECUTE     :sep_char := ',';
    SELECT     :sep_char     AS sep_char
    FROM     dual;
    PROMPT     ==========  0. string_test table  ==========
    DROP TABLE     string_test;
    CREATE TABLE     string_test
    (     grp_name     VARCHAR2 (10)
    ,     list_txt     VARCHAR2 (50)
    INSERT INTO string_test (grp_name, list_txt) VALUES ('Animal',     'amoeba,bat,cedusa,dodo');
    INSERT INTO string_test (grp_name, list_txt) VALUES ('Date',     '15-Oct-1582,16-Oct-2008');
    INSERT INTO string_test (grp_name, list_txt) VALUES ('Nothing',     NULL);
    INSERT INTO string_test (grp_name, list_txt) VALUES ('Place',     'New York');
    INSERT INTO string_test (grp_name, list_txt) VALUES ('Skip',     'Hop,,Jump');
    SELECT     *
    FROM     string_test
    ORDER BY     grp_name;
    PROMPT     ==========  Q1.  Oracle 11 Query  ==========
    WITH     cntr     AS          -- Requires Oracle 9
    (     -- Begin sub-query cntr, to generate n (1, 2, 3, ...)
         SELECT     LEVEL     AS n     -- Requires Oracle 9
         FROM     dual
         CONNECT BY     LEVEL     <= 1 +     (
                             SELECT     MAX ( REGEXP_COUNT (list_txt, :sep_char) )     -- Requires Oracle 11
                             FROM     string_test
    )     -- End sub-query cntr, to generate n (1, 2, 3, ...)
    SELECT     grp_name
    ,     n
    ,     REGEXP_SUBSTR     ( list_txt     -- Requires Oracle 10
                   , '[^' || :sep_char || ']'     -- Anything except sep_char ...
                        || '+'               -- ... one or more times
                   , 1
                   , n
                   )     AS item_txt
    FROM     string_test
    JOIN     cntr                                   -- Requires Oracle 9
    ON     n     <= 1 + REGEXP_COUNT (list_txt, :sep_char)     -- Requires Oracle 11
    ORDER BY     grp_name
    ,          n;
    /*     Notes:
         REGEXP_SUBSTR (s, '[^,]+', 1, n)
    returns the n-th item in a comma-delimited list s.
    If there are fewer than n items, it returns NULL.
    One or more consecutive characters other than comma make an item, so
    'Hop,,Jump' has two items, the second one being 'Jump'.
    The sub-query cntr produces a list of integers 1, 2, 3, ..., w
    where w is the worst-case (the largest number of items in any list).
    This actually counts separators, not items, (e.g., it counts both
    commas in 'Hop,,Jump', even though), so the w it produces may be
    larger than is really necessary.  No real harm is done.
    PROMPT     ==========  Q2. Possible Problems Fixed  ==========
    WITH     cntr     AS
    (     -- Begin sub-query cntr, to generate n (1, 2, 3, ...)
         SELECT     LEVEL     AS n
         FROM     dual
         CONNECT BY     LEVEL     <= 1 +     (
                             SELECT     MAX ( REGEXP_COUNT (list_txt, :sep_char) )
                             FROM     string_test
    )     -- End sub-query cntr, to generate n (1, 2, 3, ...)
    SELECT     grp_name
    ,     n
    ,     REGEXP_SUBSTR     ( list_txt
                   , '[^' || :sep_char || ']'     -- Anything except sep_char ...
                        || '+'               -- ... one or more times
                   , 1
                   , n
                   )     AS item_txt
    FROM     string_test
    JOIN     cntr          ON n     <= 1 + NVL     ( REGEXP_COUNT (list_txt, :sep_char)     -- Problem (1)
                                  , 0
    WHERE     REGEXP_SUBSTR     ( list_txt     -- Problem (2)
                   , '[^' || :sep_char || ']'     -- Anything except sep_char ...
                        || '+'               -- ... one or more times
                   , 1
                   , n
                   )     IS NOT NULL
    OR     list_txt     IS NULL          -- Problems (1) and (2) together
    ORDER BY     grp_name
    ,          n;
         (Possible) Problems and Fixes
    (1) If list_txt IS NULL, then REGEXP_COUNT (list_txt, :sep_char)
         returns NULL, the join condition fails, and the output
         contains nothing corresponding to the row from string_test.
         If you want a NULL item to appear in the results, use
         NVL to make sure the expression returns 0 instead of NULL.
    (2) If list_txt contains multiple consecutive sep_chars (or if it
         begins or ends with sep_char, then the original query
         will return NULL items.  To suppress these, add a WHERE
         clause to test that the item_txt to be displayed IS NOT NULL.
    PROMPT     ==========  Q3. Oracle 8.1 Query  ===========
    SELECT     grp_name
    ,     n
    ,     SUBSTR     ( list_txt
              , begin_pos
              , end_pos - begin_pos
              )     AS item_txt
    FROM     (     -- Begin sub-query to compute begin_pos and end_pos
         SELECT     grp_name
         ,     n
         ,     list_txt
         ,     INSTR     ( :sep_char || list_txt
                   , :sep_char
                   , 1
                   , n
                   )     AS begin_pos
         ,     INSTR     ( list_txt || :sep_char
                   , :sep_char
                   , 1
                   , n
                   )     AS end_pos
         FROM     string_test
         ,     (     -- Begin sub-query cntr, to generate n (1, 2, 3, ...)
              SELECT     ROWNUM     AS n
              FROM     all_objects
              WHERE     ROWNUM     <= 1 +     (
                             SELECT     MAX     ( LENGTH (list_txt)
                                       - LENGTH (REPLACE (list_txt, :sep_char))
                             FROM     string_test
              )     -- End sub-query cntr, to generate n (1, 2, 3, ...)
              cntr
         WHERE     n     <= 1 +     ( LENGTH (list_txt)
                        - LENGTH (REPLACE (list_txt, :sep_char))
         )     -- End sub-query to compute begin_pos and end_pos
    ORDER BY     grp_name
    ,          n;
    /*     Version-Dependent Features and Work-Arounds
    The code above, Q3, runs in Oracle 8.1.
    The following changes were made to Q1:
    (11) REGEXP_COUNT was introduced in Oracle 11.
         In earlier versions, to find the number of sep_chars in list_txt,
         see how much the LENGTH changes when sep_chars are removed.
    (10) REGEXP_SUBSTR was introduced in Oracle 10.
         In earlier versions, use INSTR to find where the sep_chars are,
         and use SUBSTR to get the sub-strings between them.
         (Using this technique, 'Hop,,Jump' still contains three items,
         but now item 2 IS NULL and item 3 is 'Jump'.)
    (9.a) The WITH-clause was introduced in Oracle 9
         In earlier versions, use in-line views.
    (9.b) "CONNECT BY LEVEL < constant" doesn't work in Oracle 8.
         Use ROWNUM from any sufficiently large table or view instead.
    (9.c) ANSII join notation (JOIN table_name ON ...) was introduced in Oracle 9
         In earlier versions, join condition go in a WHERE-clause.
    */

  • Parse column with csv string into table with one row per item

    I have a table (which has less than 100 rows) - ifs_tables that has two columns: localtable and Fields. Localtable is a table name and Fields contains a subset of columns from that table. Fields is a comma delimited list:  'Fname,Lname'. It looks like
    this:
    localtable         fields
    =========  =============
    customertable   fname,lname
    accounttable     type,accountnumber
    Want to end up with a new table that has one row per column. It should look like this:
    TableName             ColumnName
    ============ ==========
    CustomerTable        Fname
    CustomerTable        Lname
    AccountTable          Type
    AccountTable          AccountNumber
    Tried this code but have two issues (1) My query using the Splitfields functions gets "Subquery returned more than 1 value" (2) some of my Fields has hundreds of collumns in the commas delimited list. It will returns "Msg 530, Level 16, State
    1, Line 8. The statement terminated. The maximum recursion 100 has been exhausted before statement completion.maxrecursion greater than 100." Tried adding OPTION (maxrecursion 0) in the Split function on the SELECT statment that calls the CTE, but
    the syntax is not correct.
    Can someone help me to get this sorted out? Thanks
    DROP FUNCTION [dbo].[SplitFields]
    go
    CREATE FUNCTION [dbo].[SplitFields]
    @String NVARCHAR(4000),
    @Delimiter NCHAR(1)
    RETURNS TABLE
    AS
    RETURN
    WITH Split(stpos,endpos)
    AS(
    SELECT 0 AS stpos, CHARINDEX(@Delimiter,@String) AS endpos
    UNION ALL
    SELECT endpos+1, CHARINDEX(@Delimiter,@String,endpos+1)
    FROM Split
    WHERE endpos > 0
    SELECT 'Id' = ROW_NUMBER() OVER (ORDER BY (SELECT 1)),
    'Data' = SUBSTRING(@String,stpos,COALESCE(NULLIF(endpos,0),LEN(@String)+1)-stpos)
    FROM Split --OPTION ( maxrecursion 0);
    GO
    IF OBJECT_ID('tempdb..#ifs_tables') IS NOT NULL DROP TABLE #ifs_tables
    SELECT *
    INTO #ifs_tables
    FROM (
    SELECT 'CustomerTable' , 'Lname,Fname' UNION ALL
    SELECT 'AccountTable' , 'Type,AccountNumber'
    ) d (dLocalTable,dFields)
    IF OBJECT_ID('tempdb..#tempFieldsCheck') IS NOT NULL DROP TABLE #tempFieldsCheck
    SELECT * INTO #tempFieldsCheck
    FROM
    ( --SELECT dLocaltable, dFields from #ifs_tables
    SELECT dLocaltable, (SELECT [Data] FROM dbo.SplitFields(dFields, ',') ) from #ifs_tables
    ) t (tLocalTable, tfields) -- as Data FROM #ifs_tables
    SELECT * FROM #tempFieldsCheck

    Try this
    DECLARE @DemoTable table
    localtable char(100),
    fields varchar(200)
    INSERT INTO @DemoTable values('customertable','fname,lname')
    INSERT INTO @DemoTable values('accounttable','type,accountnumber')
    select * from @DemoTable
    SELECT A.localtable ,
    Split.a.value('.', 'VARCHAR(100)') AS Dept
    FROM (SELECT localtable,
    CAST ('<M>' + REPLACE(fields, ',', '</M><M>') + '</M>' AS XML) AS String
    FROM @DemoTable) AS A CROSS APPLY String.nodes ('/M') AS Split(a);
    Refer:-https://sqlpowershell.wordpress.com/2015/01/09/sql-split-delimited-columns-using-xml-or-udf-function/
    CREATE FUNCTION ParseValues
    (@String varchar(8000), @Delimiter varchar(10) )
    RETURNS @RESULTS TABLE (ID int identity(1,1), Val varchar(8000))
    AS
    BEGIN
    DECLARE @Value varchar(100)
    WHILE @String is not null
    BEGIN
    SELECT @Value=CASE WHEN PATINDEX('%'+@Delimiter+'%',@String) >0 THEN LEFT(@String,PATINDEX('%'+@Delimiter+'%',@String)-1) ELSE @String END, @String=CASE WHEN PATINDEX('%'+@Delimiter+'%',@String) >0 THEN SUBSTRING(@String,PATINDEX('%'+@Delimiter+'%',@String)+LEN(@Delimiter),LEN(@String)) ELSE NULL END
    INSERT INTO @RESULTS (Val)
    SELECT @Value
    END
    RETURN
    END
    SELECT localtable ,f.Val
    FROM @DemoTable t
    CROSS APPLY dbo.ParseValues(t.fields,',')f
    --Prashanth

  • STARTED IT, BUT STILL NEED HELP -- INPUTTTING CHARACTERS FROM LOADED FILE INTO TABLE, SELECTING STRINGS FROM TABLE AND PLACING IN NEW TABLE, SAVING NEW TABLE TO SPREADSHEET FILE

    I AM TRYING TO IMPORT CHARACTERS FROM A TAB DELIMITED FILE INTO A TABLE ON LABVIEW.  ONCE THE DATA IS IN THE TABLE I WANT TO BE ABLE TO SELECT INDIVIDUAL STRINGS FROM THE TABLE AND PLACE IT IN A NEW TABLE.  WHEN I CLICK ON A STRING I WOULD LIKE THE SELECTED STRING TO SHOW IN A TEXT BOX LABELED 'SELECTED STEP'  AFTER ALL THE SELECTED STRINGS IS IN THE TABLE I WOULD LIKE TO SAVE THE NEW TABLE AS ANOTHER SPREADSHEET -- TAB DELIMITED -- FILE, MAKING IT ACCESSIBLE TO OPEN.  HERE IS WHAT I HAVE SO FAR.  I CAN INPUT DATA INTO THE TABLE, BUT I CAN ONLY TRANSFER ONE STRING INTO THE TABLE I WOULD LIKE TO BE TO INPUT MULTIPLE STRINGS.    ALSO WHENEVER I TRY SAVING THE FILE, IT ALWAYS SAVES A UNKNOWN FILE, HOW CAN I GET IT TO SAVE AS A SPREADSHEET FILE.  THANKING ALL OF YOU IN ADVANCE FOR YOUR HELP!!!!!!
    Attachments:
    Selector.zip ‏30 KB

    Pondered,
       The question you are asking is the same one that you asked in: http://forums.ni.com/ni/board/message?board.id=170&message.id=132508#M132508, to which I supplied a revised version of the original vi you used (which was modified from the original one I supplied to an earlier thread). A couple of questions: 1) What does my latest not do that is in your question, 2) Why are you starting yet another thread about the same problem?  We are here trying to help, it makes it a lot easier if you keep the same problem in the same thread, it reduces duplication of effort from those that might not have been following the previous thread(s).  Those of us that don't have our "names in blue" are just doing this "for fun" (the blue names are NI employees, who may still be doing it "for fun"), and it makes it more fun if it doesn't seem (correctly or not) that our attempts are ignored.  If an answer doesn't help, or seems incomplete, post a little more detail to the same thread so that the original respondent, or someone new, can provide more information, or understand your problem better.
    P.M.
    Message Edited by LV_Pro on 07-20-2005 01:20 PM
    Putnam
    Certified LabVIEW Developer
    Senior Test Engineer
    Currently using LV 6.1-LabVIEW 2012, RT8.5
    LabVIEW Champion

  • How to parse a delimited string and insert into different columns?

    Hi Experts,
    I need to parse a delimited string ':level1_value:level2_value:level3_value:...' to 'level1_value', 'level2_value', etc., and insert them into different columns of one table as one row:
    Table_Level (Level1, Level2, Level3, ...)
    I know I can use substr and instr to get level value one by one and insert into Table, but I'm wondering if there's better ways to do it?
    Thanks!

    user9954260 wrote:
    However, there is one tiny problem - the delimiter from the source system is a '|' When I replace your test query with | as delimiter instead of the : it fails. Interestingly, if I use ; it works. See below:
    with t as (
    select 'str1|str2|str3||str5|str6' x from dual union all
    select '|str2|str3|str4|str5|str6' from dual union all
    select 'str1|str2|str3|str4|str5|' from dual union all
    select 'str1|str2|||str5|str6' from dual)
    select x,
    regexp_replace(x,'^([^|]*).*$','\1') y1,
    regexp_replace(x,'^[^|]*|([^|]*).*$','\1') y2,
    regexp_replace(x,'^([^|]*|){2}([^|]*).*$','\2') y3,
    regexp_replace(x,'^([^|]*|){3}([^|]*).*$','\2') y4,
    regexp_replace(x,'^([^|]*|){4}([^|]*).*$','\2') y5,
    regexp_replace(x,'^([^|]*|){5}([^|]*).*$','\2') y6
    from t;
    The "bar" or "pipe" symbol is a special character, also called a metacharacter.
    If you want to use it as a literal in a regular expression, you will need to escape it with a backslash character (\).
    Here's the solution -
    test@ORA11G>
    test@ORA11G> --
    test@ORA11G> with t as (
      2    select 'str1|str2|str3||str5|str6' x from dual union all
      3    select '|str2|str3|str4|str5|str6' from dual union all
      4    select 'str1|str2|str3|str4|str5|' from dual union all
      5    select 'str1|str2|||str5|str6' from dual)
      6  --
      7  select x,
      8         regexp_replace(x,'^([^|]*).*$','\1') y1,
      9         regexp_replace(x,'^[^|]*\|([^|]*).*$','\1') y2,
    10         regexp_replace(x,'^([^|]*\|){2}([^|]*).*$','\2') y3,
    11         regexp_replace(x,'^([^|]*\|){3}([^|]*).*$','\2') y4,
    12         regexp_replace(x,'^([^|]*\|){4}([^|]*).*$','\2') y5,
    13         regexp_replace(x,'^([^|]*\|){5}([^|]*).*$','\2') y6
    14  from t;
    X                         Y1      Y2      Y3      Y4      Y5      Y6
    str1|str2|str3||str5|str6 str1    str2    str3            str5    str6
    |str2|str3|str4|str5|str6         str2    str3    str4    str5    str6
    str1|str2|str3|str4|str5| str1    str2    str3    str4    str5
    str1|str2|||str5|str6     str1    str2                    str5    str6
    4 rows selected.
    test@ORA11G>
    test@ORA11G>isotope
    PS - it works for semi-colon character ";" because it is not a metacharacter. So its literal value is considered by the regex engine for matching.
    Edited by: isotope on Feb 26, 2010 11:09 AM

  • Split string into new column

    Hi All,
    Hoping you are able to help.
    I have a table of approx 16 items that I need to split,
    EG:
    CUSTOMER ACCEPTANCE - HAS BEEN DECLINED - DO NOT APPLY TO ACCOUNT
    CUSTOMER ACCEPTANCE -  HAS BEEN ACCEPTED - APPLY TO ACCOUNT
    CUSTOMER ACCEPTANCE - PENDING DECLINE - ESCALATION REQUIRED - RAISED IN PORTAL
    ESCALATION - RAISED - PENDING
    ESCALATION - NOT RAISED - STILL TO BE PROCESSED
    I need to Keep the first two sections, eg CUSTOMER ACCEPTANCE - HAS BEEN DECLINED in one column, and split off the remaining, eg DO NOT APPLY TO ACCOUNT into a new TEMP table to insert as a column into an existing table.
    With little SQL experience, I am having difficulties as they are all of different lengths / criteria etc. Some have 3 hyphens whilst others have 4+
    Is anyone able to help point me in the right direction with this request? I will be greatly appreciated.
    Kind Regards,
    BTMMP

    If you're trying to do this all in a SQL query or stored procedure, then you'll probably get better results on the SQL Server forums. However, if you're working with a PowerShell or VBScript that's doing the work, you're in the right place.
    Here's one example of how you could do what you're describing.  By the way, what do you want to do with the string "CUSTOMER ACCEPTANCE - PENDING DECLINE - ESCALATION REQUIRED - RAISED IN PORTAL"?  Should that be split into "CUSTOMER ACCEPTANCE
    - PENDING DECLINE" and "ESCALATION REQUIRED - RAISED IN PORTAL", or "CUSTOMER ACCEPTANCE - PENDING DECLINE - ESCALATION REQUIRED" and "RAISED IN PORTAL"?
    (In other words, should the script only split off whatever's after the final hyphen, or should it grab the first two pieces of text and split off everything else?)
    Here's an example in PowerShell which assumes that you want to separate out all text after the final hyphen in a string.  It uses a regular expression, though you could accomplish the same thing with Split, Join and Trim operations, if you prefer.
    $string = 'CUSTOMER ACCEPTANCE - HAS BEEN ACCEPTED - APPLY TO ACCOUNT'
    if ($string -match '(.*?)\s*-\s*([^-]*)$')
    $split = $matches[1], $matches[2]
    else
    $split = $string, ''
    Write-Host "Original String: $string"
    Write-Host "First Text : $($split[0])"
    Write-Host "Second Text : $($split[1])"

  • How to split list of columns into 2 tables in SSIS 2012?

    Hi,
    I have 200 columns in Source. Now i want to split these columns, few into Destination A and few more columns into
    Destination B. Multi cast i tried to use, but it coping all the columns . Any help would be appreciated. Thanks in Advance.
    Lets assume  i have columns  A,B,C,D,E..
    i want to move Columns A,B,D into destination A and 
    columns A,C,D,E INTO Destination B. please help me to implement this logic?

    Hi vasu_479,
    Based on your description, you want to split columns in source table into two destination tables.
    After testing the scenario in my environment, we can use Multicast to achieve your requirement. Just as you said, the Multicast would return all columns. But we can use the method below to achieve the goal:
    If the destination tables are existing tables, we can just map column A, B and D as Input Columns to the corresponding Destination Columns in the Mapping tab for destination A. Then map column A, C, D and E in destination B.
    If the destination tables are created in the Destination component, we can modify the create table query to directly create A, B and D for destination table A, create A, C, D and E for destination table B. Then there columns would be automatically mapped
    in the Mappings pane.
    If there are any other questions, please feel free to ask.
    Thanks,
    Katherine Xiong
    Katherine Xiong
    TechNet Community Support

  • Problem - insert JSON string into table in CLR function

    Hi
    I create a CLR function to insert JSON string into table.
    With this line 
    mt = JsonConvert.DeserializeObject<MyTable>(jsonStr.ToString());
    The class is OK (no error), but when I try to add the Assembly in Microsoft SQL Server Management Studio, it has error :
    Assembly 'newtonsoft.json, version=4.5.0.0, culture=neutral, publickeytoken=30ad4fe6b2a6aeed.' was not found in the SQL catalog.
    (I have Newtonsoft.Json in the Reference)
    Please help !
    Thanks

    Hi Bob
    Could you elaborate a bit more?
    I think the code is ok. The problem is when I deploy the Visual Studio creates/alters the assembly, and get the error
    Error:  SQL72014: .Net SqlClient Data Provider: Msg 6503, Level 16, State 12, Line 1 Assembly 'newtonsoft.json, version=6.0.0.0, culture=neutral, publickeytoken=30ad4fe6b2a6aeed.' was not found in the SQL catalog.
    ALTER ASSEMBLY [Database1]
        FROM 0x4D5A90000300000004000000FFFF0000B800000000000000400000000000000000000000000000000000000000000000000000000000000000000000800000000E1FBA0E00B409CD21B8014CCD21546869732070726F6772616D2063616E6E6F742062652072756E20696E20444F53206D6F64652E0D0D0A2400000000000000504500004C0103000DE411540000000000000000E00002210B010B000012000000060000000000008E3000000020000000400000000000100020000000020000040000000000000006000000000000000080000000020000000000000300608500001000001000000000100000100000000000001000000000000000000000003C3000004F00000000400000A802000000000000000000000000000000000000006000000C000000042F00001C0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000080000000000000000000000082000004800000000000000000000002E7465787400000094100000002000000012000000020000000000000000000000000000200000602E72737263000000A8020000004000000004000000140000000000000000000000000000400000402E72656C6F6300000C0000000060000000020000001800000000000000000000000000004
    An error occurred while the batch was being executed.
    Done building project "Database1.sqlproj" -- FAILED.
    This is my FillRow function. Without the bold line, the everything is fine. I can create the assembly, then create the SQL function. Done. When I call select from the SQL function, it returns 10 rows as expected.
    public static IEnumerable getTable(SqlString jsonStr)
            ArrayList resultCollection = new ArrayList();
            MyTable mt;
            //mt = JsonConvert.DeserializeObject<MyTable>(jsonStr.ToString());
            int c = 1;
            while (c < 10)
                mt = new MyTable();
                mt.GlobalId = c.ToString();
                mt.DateSet = "DS=!=" + c.ToString();
                mt.Timestamp = "TS==" + c.ToString();
                mt.PartnerId = "PI==" + c.ToString();
                mt.PartnerUserId = "PUI=" + c.ToString();
                mt.UserIP = "UIP=" + c.ToString();
                mt.UserAgent = "UG=" + c.ToString();
                mt.Referer = "R=" + c.ToString();
                resultCollection.Add(mt);
                c++;
            //resultCollection.Add(mt);
            return resultCollection;

  • Split single line entry into mutliple table entries using BODS.

    Hi All,
    I have a question on how to resolve splitting a single entry input into mutliple line entries using BODS.
    Example we have Column 1, Column 2, Column 3 and the output will have 3 lines with Line 1 value from Column 1, Line 2 value from Column 2 and Line 3 value from Column 3?
    Is there a loop that can be utilized inside a Data Flow?
    What I had thought of is current using a CASE and a MERGE to resolve this.
    Are there a better solution to this?
    Thanks,
    Tim

    Hi Maurice,
    Thanks for the reply. It's more based on a condition so say if column 1 has a value, then you get row 1 created, if column 2 has a value then only row 2 gets created. Also, the source table contains multiple columns and not all will be pivoted into rows, just a certain particular columns.
    Anyway, i had resolved this at the moment via CASE to split single row input into individual Queries and MERGE them back creating multiple rows.
    Would like to know if anyone has a better 'performance wise' solution.

  • How to Break this String and put into a Table

    Hi all,
    Currently i working on the Reading of Csv file.THe Csv file wil be stored as BLOB in one table.
    The Format of the Csv file is
    EMPCODE :DATEOFBIRTH
    312089 ,12/01/1984
    321456 ,03/05/1980
    120212 ,04/08/1987
    312456 ,23/12/1977
    311110 ,12/04/1998
    323232 ,20/06/1990
    UPLOAD_BLOB
    column     Datatype
    UploadId Number
    File_details BLOB
    And i reading the BLOB in one procedure and i m getting the String as like this ---->
    "312089 ,12/01/1984
    321456 ,03/05/1980
    120212 ,04/08/1987
    312456 ,23/12/1977
    311110 ,12/04/1998
    323232 ,20/06/1990"
    I am Dont know how to Parse this String and put in table
    While 1<STRING.LENGTH
    LOOP
    EMPCODE=SUBSTRING();
    DATEOFBIRTH=SUBSTRING();
    INSERT INTO TABLE VALID_EMPCODE(EMPCODE,DATEOFBIRTH)VALUES(......);END LOOP
    VALID_EMPCODE
    EMPCODE VARCHAR2(30)
    DATEOFBIRTH VARCHAR2(15)
    Can any one tell me how to parse this whole string and break them

    Duplicate post
    How to Break this String and put into a Table

Maybe you are looking for