How to Split the string using Substr and instr using loop condition

Hi every body,
I have below requirement.
I need to split the string and append with single quotes('') followed by , (comma) and reassign entire values into another variable. so that i can use it where clause of update statement
for example I am reciveing value as follows
ALN varchar2(2000):=(12ERE-3MT-4Y,4IT-5O-SD,OP-K5-456,P04-SFS9-098,90P-SSF-334,3434-KJ4-O28,AS3-SFS0-J33,989-3KL-3434);
Note: In the above variable i see 8 transactions, where as in real scenario i donot how many transaction i may recive.
after modification i need above transactions should in below format
ALTR Varchar2(2000):=('12ERE-3MT-4Y','4IT-5O-SD','OP-K5-456','P04-SFS9-098','90P-SSF-334','3434-KJ4-O28','AS3-SFS0-J33','989-3KL-3434');
kindly help how to use substr and instr in normal loop or for loop or while loop while modifying the above transactions.
Please help me to sort out this issue.
Many Thanks.
Edited by: user627525 on Dec 15, 2011 11:49 AM

Try this - may not be the best way but...:
create or replace type myTableType as table of varchar2(255)
declare
v_array mytabletype;
v_new_str varchar2(4000);
function str2tbl
         (p_str   in varchar2,
          p_delim in varchar2 default '.')
         return      myTableType
    as
        l_str        long default p_str || p_delim;
         l_n        number;
         l_data     myTableType := myTabletype();
    begin
        loop
            l_n := instr( l_str, p_delim );
            exit when (nvl(l_n,0) = 0);
            l_data.extend;
            l_data( l_data.count ) := ltrim(rtrim(substr(l_str,1,l_n-1)));
            l_str := substr( l_str, l_n+length(p_delim) );
        end loop;
        return l_data;
   end;
begin
  v_array := str2tbl ('12ERE-3MT-4Y,4IT-5O-SD,OP-K5-456,P04-SFS9-098,90P-SSF-334,3434-KJ4-O28,AS3-SFS0-J33,989-3KL-3434', ',');
      FOR i IN 1 .. v_array.COUNT LOOP
         v_new_str := v_new_str || ''''||v_array(i)||'''' || ',';
      END LOOP;
   dbms_output.put_line(RTRIM(v_new_str, ','));
end;  
OUTPUT:
=======
'12ERE-3MT-4Y','4IT-5O-SD','OP-K5-456','P04-SFS9-098','90P-SSF-334','3434-KJ4-O28','AS3-SFS0-J33','989-3KL-3434'HTH
Edited by: user130038 on Dec 15, 2011 12:11 PM

Similar Messages

  • How To Split the String for "."

    Hi Friends
    I am Using Following Code to Split one String.
    String str = "Jeetendra.choudhary";
    String[] sp_str = str.split(".");
    wdComponentApi.getMessageManager.reportSuccess(str[0]);
    wdComponentApi.getMessageManager.reportSuccess(str[1]);
    but its throwing null pointer exception. 
    when i am using following code its working fine.
    String str = "Jeetendra/choudhary";
    String[] sp_str = str.split("/");
    wdComponentApi.getMessageManager.reportSuccess(str[0]);
    wdComponentApi.getMessageManager.reportSuccess(str[1]);
    what may be the issue and how to split the string with "." ?
    Thanks & Regards
    Jeetendra

    "." is a special character.
    Use
    str.split("\\.");
    Regards
    Benjamin
    Edited by: Benjamin Hansen on Dec 29, 2009 7:52 AM

  • How to split the blob byte array and insert in oracle

    how to split the blob byte array and insert in oracle
    I am having a string which is of more than lenght 4000 so i am using BLOB datatype as input to get the string.
    need to split the blob in oracle and store in the different column
    The string is of bytearray i need to strore it in each column based on the byte array.

    this will be my input i need to split the above and store it in different columns in a table.
    for spliting say
    Column1 -1 byte
    Column2-3 byte
    Column3-5 byte
    ColumnN-5 byte
    Table will have corresponding data type
    Column1 - number(10,2)
    Column2 - Float
    Column3 - Float
    ColumnN-Float
    here Column2 datatype is float but it will always have 3 byte information.
    where as Column3 datatype is also float but it will always have 5 byte information.
    Say N is Column 120

  • How to split the string by datetime in sql

    Hi,
    How to split the string by datetime in sql, I've a table with comments column stores comments by datetime, while selecting I want to split and show as in rows by each jobref.
    can anyone help me in this please.
    Thanks,

    declare @callcentre table (comments varchar(max),lbiref varchar(200))
    insert into @callcentre
    select '(28/10/2014 14:56:14) xyz ..... call  logged   (28/10/2014 14:56:58) xyz ..... call updated   (28/10/2014 14:57:41)xyz ..... call updated','Vi2910201'
    insert into @callcentre
    select '(29/10/2014 14:56:14) xyz ..... call  logged   (29/10/2014 14:56:58) xyz ..... call updated   (29/10/2014 14:57:41)xyz ..... call updated','Vi2910202'
    insert into @callcentre
    select '(30/10/2014 14:56:14) xyz ..... call  logged   (30/10/2014 14:56:58) xyz ..... call updated  
    output:
    1) 28/10/2014 14:56:14, (28/10/2014 14:56:14) xyz ..... call  logged ,'Vi2910201'
     2) 28/10/2014 14:56:58 ,(28/10/2014 14:56:58) xyz ..... call updated ,'Vi2910201'
    3) 28/10/2014 14:57:41,  (28/10/2014 14:57:41)xyz ..... call updated,'Vi2910201'
    4) 28/10/2014 14:56:14, (28/10/2014 14:56:14) xyz ..... call  logged ,'Vi2910202'
     5) 28/10/2014 14:56:58 ,(28/10/2014 14:56:58) xyz ..... call updated ,'Vi2910202'
    6) 28/10/2014 14:57:41,  (28/10/2014 14:57:41)xyz ..... call updated,'Vi2910202'
    7) 28/10/2014 14:56:14, (28/10/2014 14:56:14) xyz ..... call  logged ,'Vi2910203'
     8) 28/10/2014 14:56:58 ,(28/10/2014 14:56:58) xyz ..... call updated ,'Vi2910203'
    Thanks,
    See this illustration
    declare @callcentre table (comments varchar(max),lbiref varchar(200))
    insert into @callcentre
    select '(28/10/2014 14:56:14) xyz ..... call logged (28/10/2014 14:56:58) xyz ..... call updated (28/10/2014 14:57:41)xyz ..... call updated','Vi2910201'
    insert into @callcentre
    select '(29/10/2014 14:56:14) xyz ..... call logged (29/10/2014 14:56:58) xyz ..... call updated (29/10/2014 14:57:41)xyz ..... call updated','Vi2910202'
    insert into @callcentre
    select '(30/10/2014 14:56:14) xyz ..... call logged (30/10/2014 14:56:58) xyz ..... call updated','Vi2910203'
    SELECT LEFT(p.u.value('.[1]','varchar(max)'),CHARINDEX(')',p.u.value('.[1]','varchar(max)'))-1) AS [Date],
    '(' + p.u.value('.[1]','varchar(max)') AS comments,
    lbiref
    FROM
    SELECT lbiref,CAST('<Root>' + STUFF(REPLACE(comments,'(','</Data><Data>'),1,7,'') + '</Data></Root>' AS XML) AS x
    FROM @callcentre c
    )t
    CROSS APPLY x.nodes('/Root/Data')p(u)
    and the output
    Date comments lbiref
    28/10/2014 14:56:14 (28/10/2014 14:56:14) xyz ..... call logged Vi2910201
    28/10/2014 14:56:58 (28/10/2014 14:56:58) xyz ..... call updated Vi2910201
    28/10/2014 14:57:41 (28/10/2014 14:57:41)xyz ..... call updated Vi2910201
    29/10/2014 14:56:14 (29/10/2014 14:56:14) xyz ..... call logged Vi2910202
    29/10/2014 14:56:58 (29/10/2014 14:56:58) xyz ..... call updated Vi2910202
    29/10/2014 14:57:41 (29/10/2014 14:57:41)xyz ..... call updated Vi2910202
    30/10/2014 14:56:14 (30/10/2014 14:56:14) xyz ..... call logged Vi2910203
    30/10/2014 14:56:58 (30/10/2014 14:56:58) xyz ..... call updated Vi2910203
    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

  • How to split the string from character position.

    HI ALL,
    I need to split the string like this.
    example:
    String = "HelloWorld"
    mid("HelloWorld", 2, 5);
    it should print   "ello"
    menas mid is functiuon it will split "HelloWorld" from 2nd character to 5th character and prints "ello".
    This one how to do in labview.
    Regards
    Punith

    String Subset is the function you are looking for.
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines

  • How to split a string into tokens and iterate through the tokens

    Guys,
    I want to split a string like 'Value1#Value2' using the delimiter #.
    I want the tokens to be populated in a array-like (or any other convenient structure) so that I can iterate through them in a stored procedure. (and not just print them out)
    I got a function on this link,
    http://www.orafaq.com/forum/t/11692/0/
    which returns a VARRAY. Can anybody help me how to iterate over the VARRAY, or suggest a different alternative to the split please ?
    Thanks.

    RTFM: http://download-uk.oracle.com/docs/cd/B19306_01/appdev.102/b14261/collections.htm#sthref1146
    or
    http://www.oracle-base.com/articles/8i/Collections8i.php

  • How to split the string?

    Hi Experts,
    Can anyone explain me with code how to separate the single character from the given input string?
    For Example: Input String str = 'RAGHU'
    Output should be:
    R
    RA
    RAGH
    RAGHU
    RAGH
    RAG
    RA
    R
    Can anyone help me with code for above required output?
    Thanks in Advance,
    Regards,
    Raghu.

    HI,
    sy-index will give u the iteration number.
    first of all in this program u are counting the length of the string and it was in variable LEN.
    we are always printing the string from 0 index(1st character) to POS number of characters.
    length is 5 so LNG = 5 * 2 = 10 and LNG = 10 - 1 = 9.and first sy-index = 1.so,1 <= 5 so POS = 0 + 1 = 1. it is printing the first char
    second sy-index = 2.so,2 <= 5 so POS = 1 + 1 = 2. it is printing the first two chars
    third sy-index = 3.so,3 <= 5 so POS = 2 + 1 = 3. it is printing the first three chars
    forth sy-index = 4.so,4 <= 5 so POS = 3 + 1 = 4. it is printing the first four chars
    fifth sy-index = 5.so,5 <= 5 so POS = 4 + 1 = 5. it is printing the first five chars
    sixth sy-index = 6.so,6 > 5 so POS = 5 - 1 = 4. it is printing the first four chars
    seventh sy-index = 7.so,7 > 5 so POS = 4 - 1 = 3. it is printing the first three chars
    eighth sy-index = 8.so,8 > 5 so POS = 3 - 1 = 2. it is printing the first two chars
    ninth sy-index = 9.so,9 > 5 so POS = 2 - 1 = 1. it is printing the first char
    rgds,
    bharat.

  • Using Substr and Instr together

    Hi All,
    I have a string like 'Employee_id,employee_name,employee_ssn,employee_ps'
    I would like to extract all the four columns individually in a single statement.
    For ex:
    select SUBSTR('Employee_id,employee_name,employee_ssn,employee_ps',1,
    INSTR('Employee_id,employee_name,employee_ssn,employee_ps',',',1,1)-1) from dual;
    this gives me Employee_id. The same way how do i get the other coulmn names by comma position.
    Pls help me out.
    Please note that the column names have to be extracted depending on the comma position.
    Thanks.

    You can use regular expressions if you're running an Oracle version that's 10g or more recent, to make it very simple:
    Connected to Oracle Database 11g Enterprise Edition Release 11.2.0.1.0
    Connected as FSITJA
    SQL>
    SQL> select regexp_substr('Employee_id,employee_name,employee_ssn,employee_ps', '[^,]+', 1, 1) col_1,
      2         regexp_substr('Employee_id,employee_name,employee_ssn,employee_ps', '[^,]+', 1, 2) col_2,
      3         regexp_substr('Employee_id,employee_name,employee_ssn,employee_ps', '[^,]+', 1, 3) col_3,
      4         regexp_substr('Employee_id,employee_name,employee_ssn,employee_ps', '[^,]+', 1, 4) col_4
      5    from dual;
    COL_1       COL_2         COL_3        COL_4
    Employee_id employee_name employee_ssn employee_ps
    SQL>

  • How can I Split the String in to different strings

    Hi All,
    I have created a table A
    If i select * from A
    Result is :
    1,2,3,4 - Line 1
    11,222,3222,422 - Line 2
    Now i what to split the data like by using substr and instr
    A , B , C , D
    1 2 3 4
    11 222 3222 422
    Can any one help me in this query,i need the full query..pls
    Regards

    excuse me..
    it's unclear ..
    Now i what to split the data like by using substr and instr
    A , B , C , D
    1 2 3 4
    11 222 3222 422
    are u trying to select same result from table A to other tables B,C,D
    what r the fields number u have,what their datatypes..?
    Regards,
    Abdetu..

  • How to split a string for 2 different matching patterns?

    hey guys
    i'm trying to split a string, using .split(regular expression), if two different pattern matches but i don't know the exact syntax for it. I want to split the string from letters and punctuations.
    This is what i'm doing, obviously it's not working, i'm not too sure if syntax are correct.
    String inputDigit [] = input.split("([a-zA-Z]) (\\p{Punct})");Please help me with this, thank you!

    Can you describe in more detail what you're trying to
    accomplish?ok, basically if you have a string which consists of letters, digits and punctuations. All i'm trying to do or want to do is store all digist within that string into an array. Therefore, i'm using split method to split the string wherever you find a letter or a punctuation. But i don't know what is syntax for using two different patterns at the same time.
    // For example if you have a string "Eeyore 61 2.986PoohPiglet007Kanga-23"
    // i only want: 61 2 986 007 23. I know i can use substring // but that would be a slightly long process

  • How to split a string around "." expression

    My code is:
    public String removeExtn(String resource){
              String[] splittedName = resource.split(".");
    System.out.println("LENGHT IS: "+ splittedName.length);
              if(splittedName.length >= 3)
                   resource = splittedName[0]+ "." + splittedName[1];
              return resourceName;
         * @param args
         public static void main(String[] args) {
              Test obj = new Test();          
              System.out.println(obj.removeExtn("myfile.xml.sample"));
    But it doesn't split the string around "." and given the arraylength 0. But if I try to use any another character (e.g. "," or ";") it works perfectly fine.
    Please help me.
    Thanks in advance.
    Mansi

    Hi mansi,
    I had a same kind of problem a few days back.
    What I learned was the split() method has a string expression in it, which is usually noted as regex .
    'Regex' is just a short form for 'regular expression'
    You may directly use the string variable you would split around in some cases or may want to use a '\\' before some of the characters.
    I can't place whole information here .So, let me give you that sun site link I read it from.
    This link deals with the whole string class.
    You may want to ctrl+F and split to read on split method.
    http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.htmlThis link talks about the regular expressions
    http://java.sun.com/j2se/1.4.2/docs/api/java/util/regex/Pattern.html#sumI got his for you from that link :
    \p{Punct} Punctuation: For One of !"#$%&'()*+,-./:;<=>?@[\]^_`{|}~ This is for your knowledge.
    And if you want a quick fix just for your code...
    that'ld be using a
    split(\p{.}) in place where u used a split(.)I have not tried that ...but u may want to!
    Hope that helps.
    Message was edited by:
    Kishorei20
    Message was edited by:
    Kishorei20

  • How to get the NT user id and passwd

    Hi,
    How to get the NT user id and passwd using form 6i

    You cannot get the password. Password are stored in an encrypted format. Almost never decrypted (as a security meassure). Authentication is performed by encrypting the supplied password and matching that against the stored encrypted password.
    Think about it.. just how dangerous it will be to have a function that can dump NT users and their passwords for you. How can you ever expect to "simply decrypt a password"?
    As for getting the user name. See the Win32 kernel API call GetCurrentUser(). Also note that there is a big difference as to the owner/user of a server process/thread versus the end-user of client application (possibly running on another PC) that is making the call to the server.
    Of course, none of this is related to SQL or PL/SQL - which is what I believe the subject matter of this forum is... Kindly suggest that in future you pay attention to posting the correct subject material to the correct forum.

  • Substri and instr problem --Please help

    Hi ,
    I would like to get the find tablename starts with 'EXP' using substring and instring . I am using oracle 9i. Please help me out
    Example : 'Schema.explogtable'
    I will use table name ' EXP' in one of my procedure as input parameter to procedure
    If tablename= substr('schema.explogtable','instr('schema.explog','.',1,3) then
    Execute Procedure1('tablename')
    Else
    Execute procedure2('tablename')
    I would appreciate your help
    Regards,
    Clarkc

    ClarkC,
    Here just replace procedure1 and procedure2 with your procedure names;
    create table temp_table
    ( table_name varchar2(30)
    insert into temp_table values ('TESTME.MY_OBJECTS');
    insert into temp_table values ('TESTME.OBJECTS');
    insert into temp_table values ('ABC.ECFOBJECTLOG');
    insert into temp_table values ('XYZ.BDEOBJECTTABLE');
    insert into temp_table values ('ABC.ABCTABLE');
    insert into temp_table values ('ZYD.CLIENTTABLE');
    insert into temp_table values ('NMS.CLIENTLOGTABLE');
    COMMIT;
    pl/sql anonymous blocks  I defined 2 variables for readibility and understanding
    DECLARE
       CURSOR tcur
       IS
          SELECT table_name
          FROM temp_table;
       table_name   VARCHAR2 (40);
       my_table     VARCHAR2 (40);
    BEGIN
       FOR cur IN tcur
       LOOP
          my_table     := NULL;
          my_table     := cur.table_name;
          table_name   := SUBSTR (my_table, INSTR (my_table, '.') + 1);
          IF (table_name LIKE ('%OBJ%'))
          THEN
             DBMS_OUTPUT.put_line ('table_name containing OBJ=' || table_name);
             -- NOTE : CALL YOUR PROCEDURE1 HERE for tables containing OBJ;
            procedure1(table_name);
          ELSE
             DBMS_OUTPUT.put_line('table_name  not containing OBJ=' || table_name);
               -- NOTE : CALL YOUR PROCEDURE2 HERE for tables not containing OBJ;
            procedure2(table_name);
          END IF;
       END LOOP;
    EXCEPTION
       WHEN OTHERS
       THEN
          DBMS_OUTPUT.put_line (SUBSTR (SQLERRM, 1, 300));
          RAISE;
    END;
    Here is the output of the above block
    table_name containing OBJ=MY_OBJECTS
    table_name containing OBJ=OBJECTS
    table_name containing OBJ=ECFOBJECTLOG
    table_name containing OBJ=BDEOBJECTTABLE
    table_name  not containing OBJ=ABCTABLE
    table_name  not containing OBJ=CLIENTTABLE
    table_name  not containing OBJ=CLIENTLOGTABLEHope this helps
    Regards
    Edited by: OrionNet on Jan 17, 2009 11:48 AM

  • How to split a string using IndexOf?

    How would you split a string using indexOf and not using the .split method?
    Any help is appreciated :D
    Message was edited by:
    billiejoe

    would it be better to use the first or the second?
    int      indexOf(int ch)
    Returns the index within this string of the first occurrence of the specified character.
    int      indexOf(int ch, int fromIndex)
    Returns the index within this string of the first occurrence of the specified character, starting the search at the specified index.
    I think the second would be helpful. so how do i read it?

  • How to create the servlet as acontroller  and how to use it

    how to create the servlet as acontroller and how to use it

    >
    John
    Please update your forum profile with a real handle instead of "914824".
    When you have a problem you'll get a faster, more effective response by including as much relevant information as possible upfront. This should include:
    <li>Full APEX version
    <li>Full DB/version/edition/host OS
    <li>Web server architecture (EPG, OHS or APEX listener/host OS)
    <li>Browser(s) and version(s) used
    <li>Theme
    <li>Template(s)
    <li>Region/item type(s)
    With APEX we're also fortunate to have a great resource in apex.oracle.com where we can reproduce and share problems. Reproducing things there is the best way to troubleshoot most issues, especially those relating to layout and visual formatting. If you expect a detailed answer then it's appropriate for you to take on a significant part of the effort by getting as far as possible with an example of the problem on apex.oracle.com before asking for assistance with specific issues, which we can then see at first hand.
    I am going to have over 50 buttons in a page, Why? This would be a most unusual UI paradigm. I've never seen such a page, which suggests that whatever you want to do is normally done another way. Please explain the requirement in more detail.
    just wanted to know if its possible to do something like this in java.
    Java is not used in programming APEX UI behaviour. Java and JavaScript may share initial syllables, but they are not closely related.
    It's possible to achieve a great deal in JavaScript, but a clear definition of the requirements is necessary. Do you mean the buttons should be dynamically generated? If so, yes, this is possible in JavaScript. What would drive the process?
    Also, i would like to have dynamic action on it, for example, when the button is pressed, fill a string of text into other items(text field) within the page. Without more detail its not possible to make any specific suggestions. For example, I certainly would not want to create 50+ individual dynamic actions relating to different buttons.

Maybe you are looking for

  • How to use recovery dvd on new hard drive, install window 7

    hello, i have trouble with my laptop. my hard drive got bad sectors and now i need to replace my hdd to new one. im not sure how to reinstall window 7 on my new hdd. is it possible to install operating system on new hard drive using recovery disk? an

  • Broken screen can I use a projector?

    Hello, On a flight to switzerland my screen was crushed on the airplane .... now in Switzerland and want to use my computer but the screen is not useable at all, if I buy cables can I use my computer by hooking it up to a projection screen or tv? If

  • Subtotal price, net due date, PPD discount, damage discount requirement

    Hi all, I have the following requirements for a change in a user exit. Can you please help me, i need to know which table and what field to get them from. 1.) damage discount 2.) PPD discount = ZPDZ in header level 3.) subtotal price = unit price * q

  • Where has my incoming mail gone ?

    Guy Plasschaert email : [email protected] Comments : I wanted to delete an address from my address-book. On the address-card I marked the to-delete-name and clicked "delete" - it didn't work - I couldn't delete the address; I went in my menu to "Post

  • Service Call Issue

    Hi Experts,      While Try to add Service Call document, Getting this error. [Microsoft][SQL Server Native Client 10.0]String data, right truncation 'Service Calls' (OSCL) Regards Mohamed Yousuf Ali M I