Codes to insert comma-delimited string ...
DBAsupport.com Forums - Powered by vBulletin
Results 1 to 5 of 5

Thread: Codes to insert comma-delimited string ...

  1. #1
    Join Date
    Apr 2001
    Posts
    13

    Question

    into a table? I need some help in figuring out how to insert something like: 12, 23, 24, 78, ... which gets passed on to me into a table:

    Column
    ---------
    12
    23
    24
    78

    I would appreciate your coach. thanks!

  2. #2
    Join Date
    Aug 2000
    Posts
    462
    zee,

    If you are receiving this data as a string, and wish to insert each value separately into a table, you could create a stored procedure which takes the string as input, parses it and does the inserts.

    I'll give you some code later tonight if you don't get it done. Let me know here.

  3. #3
    Join Date
    Apr 2001
    Posts
    13
    Thanks Kmesser! I'll give it a shot...haven't found a way to parse it correctly yet so I would appreciate any tips.

  4. #4
    Join Date
    May 2000
    Posts
    58
    Try this piece of code.

    declare
    str varchar2(200) := '123,456,789,90000,1,2,3,5,78,90,' ;
    stpos number := 1;
    endpos number ;
    begin
    for i in 1..length(translate(str,',0123456789',','))+1
    loop
    endpos := instr ( str ,',',stpos ) ;
    dbms_output.put_line( substr( str,stpos,abs(endpos - stpos )) ) ;
    stpos := endpos + 1 ;
    end loop ;
    end ;

  5. #5
    Join Date
    Apr 2001
    Posts
    13
    It works! Thank you Victoria! I was playing with the substr and instr...but this code simple works great.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Click Here to Expand Forum to Full Width