Home » SQL & PL/SQL » SQL & PL/SQL » separate string by comma (Oracle 11g)
separate string by comma [message #647143] Wed, 20 January 2016 08:24 Go to next message
mape
Messages: 298
Registered: July 2006
Location: Slovakia
Senior Member
Hello

I need advice how is a possible to create select for separate string by comma.

For example, one record looks like:

'ZMAZ','DVBS','1MS8YGUI','','00541845675','ADB 2850ST','00541845675','DVBS - Set-top-box','CXWA12119027552AB','02025219100','','','1MS8YGUI','Váhovce','','02025219100','RENT','','M-2R1WH-1','DVBSNonHardDrive', '1-2BTKY7W','','','','','',''

Whole record is separated by comma and I would like to get every of informations into the columns.

Does anybody knows how to do that right?

Thanks a lot

Regards

Re: separate string by comma [message #647144 is a reply to message #647143] Wed, 20 January 2016 08:31 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
>Does anybody knows how to do that right?

you do it right by following Posting Guideline
Re: separate string by comma [message #647150 is a reply to message #647143] Wed, 20 January 2016 09:58 Go to previous messageGo to next message
Michel Cadot
Messages: 68641
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

This is a FAQ.

Re: separate string by comma [message #647167 is a reply to message #647150] Thu, 21 January 2016 00:45 Go to previous messageGo to next message
msol25
Messages: 396
Registered: June 2011
Senior Member
Dear Mape,

This is very basic question and not getting how you are putting this query.

Anyway you can resolve your issue by creating table and load that records into table using sqlldr/External Table/utl_file etc.

Please refer below url for sqlldr:

http://www.orafaq.com/wiki/SQL*Loader_FAQ


I hope after loading data into table you can check data in column as per your requirement.

[Updated on: Thu, 21 January 2016 00:47]

Report message to a moderator

Re: separate string by comma [message #647193 is a reply to message #647143] Thu, 21 January 2016 16:28 Go to previous message
Bill B
Messages: 1971
Registered: December 2004
Senior Member
I loaded the data into a table called my_test and wrote the following data to parse it down. Check it out

DECLARE
   TYPE Test_type IS TABLE OF VARCHAR2 (100);

   Parse_it        Test_type;
   L_comma_index   PLS_INTEGER;
   L_index         PLS_INTEGER := 1;
   String          VARCHAR2 (4000);
BEGIN
  PARSE_IT := TEST_TYPE();
  SELECT A.MYDATA
  INTO STRING
  FROM MY_TEST A;
  
  STRING := REPLACE(STRING,'''');
   LOOP
      L_comma_index := INSTR (String, ',', L_index);
      EXIT WHEN L_comma_index = 0;
      Parse_it.EXTEND;
      Parse_it (Parse_it.COUNT) := SUBSTR (String, L_index, L_comma_index - L_index);
      L_index := L_comma_index + 1;
   END LOOP;

   DBMS_OUTPUT.Put_line ('TABLE LENGTH :' || l_INDEX);
   DBMS_OUTPUT.Put_line ('TABLE COUNT  :' || Parse_it.COUNT);

   FOR I IN 1 .. Parse_it.COUNT
   LOOP
      DBMS_OUTPUT.Put_line (NVL(Parse_it (I),'<null>'));
   END LOOP;
END;
/
Previous Topic: Unable to pass 1st value into the query
Next Topic: INSERT into a Partition
Goto Forum:
  


Current Time: Thu Apr 18 14:55:53 CDT 2024