The following query is very useful for converting the data in a single column into a row so the all the values can be extracted from a table into variables of different name. Using cursor it is difficult to get all the values from single column into variables of different name.
Example of sample data available -
Required format into which data needs to be converted -
Query which can be used for above purpose -
SELECT MAX(DECODE(level,1,regexp_substr(str,'[^,]+',1,level))) AS val1 ,
MAX(DECODE(level,2,regexp_substr(str,'[^,]+',1,level))) AS val2 ,
MAX(DECODE(level,3,regexp_substr(str,'[^,]+',1,level))) AS val3 ,
MAX(DECODE(Level,4,Regexp_Substr(Str,'[^,]+',1,Level))) AS Val4 ,
MAX(DECODE(level,5,regexp_substr(str,'[^,]+',1,level))) AS val5 ,
MAX(DECODE(level,6,regexp_substr(str,'[^,]+',1,level))) AS val6 ,
MAX(DECODE(level,7,regexp_substr(str,'[^,]+',1,level))) AS val7 ,
MAX(DECODE(level,8,regexp_substr(str,'[^,]+',1,level))) AS val8 ,
MAX(DECODE(Level,9,Regexp_Substr(Str,'[^,]+',1,Level))) AS Val9 ,
MAX(DECODE(Level,10,Regexp_Substr(Str,'[^,]+',1,Level))) AS Val10 ,
MAX(DECODE(Level,10,Regexp_Substr(Str,'[^,]+',1,Level))) AS Val11 ,
MAX(DECODE(Level,10,Regexp_Substr(Str,'[^,]+',1,Level))) AS Val12 ,
MAX(DECODE(Level,10,Regexp_Substr(Str,'[^,]+',1,Level))) AS Val13 ,
MAX(DECODE(Level,10,Regexp_Substr(Str,'[^,]+',1,Level))) AS Val14 ,
MAX(DECODE(Level,10,Regexp_Substr(Str,'[^,]+',1,Level))) AS Val15
INTO l_value_id1 ,
l_value_id2 ,
l_value_id3 ,
l_value_id4 ,
l_value_id5 ,
l_value_id6 ,
l_value_id7 ,
l_value_id8 ,
l_value_id9 ,
l_value_id10 ,
l_value_id11 ,
l_value_id12 ,
l_value_id13 ,
l_Value_Id14 ,
l_value_id15
FROM (
SELECT Listagg (column_to_convert,',') Within Group (Order By column_to_convert) Str
FROM Table_Name
WHERE 1 = 1
GROUP BY group_by_column
) Tmp
CONNECT BY regexp_substr(str,'[^,]+',1,level) IS NOT NULL;
Example of sample data available -
Required format into which data needs to be converted -
Query which can be used for above purpose -
SELECT MAX(DECODE(level,1,regexp_substr(str,'[^,]+',1,level))) AS val1 ,
MAX(DECODE(level,2,regexp_substr(str,'[^,]+',1,level))) AS val2 ,
MAX(DECODE(level,3,regexp_substr(str,'[^,]+',1,level))) AS val3 ,
MAX(DECODE(Level,4,Regexp_Substr(Str,'[^,]+',1,Level))) AS Val4 ,
MAX(DECODE(level,5,regexp_substr(str,'[^,]+',1,level))) AS val5 ,
MAX(DECODE(level,6,regexp_substr(str,'[^,]+',1,level))) AS val6 ,
MAX(DECODE(level,7,regexp_substr(str,'[^,]+',1,level))) AS val7 ,
MAX(DECODE(level,8,regexp_substr(str,'[^,]+',1,level))) AS val8 ,
MAX(DECODE(Level,9,Regexp_Substr(Str,'[^,]+',1,Level))) AS Val9 ,
MAX(DECODE(Level,10,Regexp_Substr(Str,'[^,]+',1,Level))) AS Val10 ,
MAX(DECODE(Level,10,Regexp_Substr(Str,'[^,]+',1,Level))) AS Val11 ,
MAX(DECODE(Level,10,Regexp_Substr(Str,'[^,]+',1,Level))) AS Val12 ,
MAX(DECODE(Level,10,Regexp_Substr(Str,'[^,]+',1,Level))) AS Val13 ,
MAX(DECODE(Level,10,Regexp_Substr(Str,'[^,]+',1,Level))) AS Val14 ,
MAX(DECODE(Level,10,Regexp_Substr(Str,'[^,]+',1,Level))) AS Val15
INTO l_value_id1 ,
l_value_id2 ,
l_value_id3 ,
l_value_id4 ,
l_value_id5 ,
l_value_id6 ,
l_value_id7 ,
l_value_id8 ,
l_value_id9 ,
l_value_id10 ,
l_value_id11 ,
l_value_id12 ,
l_value_id13 ,
l_Value_Id14 ,
l_value_id15
FROM (
SELECT Listagg (column_to_convert,',') Within Group (Order By column_to_convert) Str
FROM Table_Name
WHERE 1 = 1
GROUP BY group_by_column
) Tmp
CONNECT BY regexp_substr(str,'[^,]+',1,level) IS NOT NULL;