separate string by comma [message #647143] |
Wed, 20 January 2016 08:24 |
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 #647193 is a reply to message #647143] |
Thu, 21 January 2016 16:28 |
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;
/
|
|
|