-1
SET v_ArrayLength= ARRAY_COUNT(ARRAY_SPLIT(p_SeasonsStr, ','));
    FOR v_ArrayPos in 1 .. v_ArrayLength LOOP 

    IF  (v_ArrayPos<>v_ArrayLength) THEN
        SET v_SeasonsStrs= v_SeasonsStrs||GET_VALUE_VARCHAR(ARRAY_SPLIT(p_SeasonsStr, ','),v_ArrayPos )||'_'||v_ArrayPos||',';
    ELSE
        SET v_SeasonsStrs= v_SeasonsStrs||GET_VALUE_VARCHAR(ARRAY_SPLIT(p_SeasonsStr, ','),v_ArrayPos )||'_'||v_ArrayPos;       
    END IF;

END LOOP;

how i can MIGRATE THIS CODE FROM NETEZZA TO DB2?

trump4ik
  • 1
  • 1
  • Great! Formatted text is much better than images! – jarlh Oct 11 '19 at 08:30
  • Question cannot be answered without knowing the target Db2-server operating-system (Z/OS, i-series, Linux/Unix/Windows), and the Db2-version. – mao Oct 11 '19 at 13:46

1 Answers1

0

It would be good especially for those who are not familiar with Netezza functions, if you provided some data sample in p_SeasonsStr and the result expected in v_SeasonsStr.
The code above probably can be amended just to a single select statement in Db2 for LUW:

select listagg(tok||'_'||seq, ',') within group (order by seq)
into v_SeasonsStrs
from xmltable('for $id in tokenize($s, ",") return <i>{string($id)}</i>' 
passing 
-- 'str1,str2,str3'
p_SeasonsStr
as "s"
columns 
  seq for ordinality
, tok varchar(50) path '.'
) t;

If you comment out the rows with a variable and a parameter and uncomment the commented out row, and run the statement you got, the result is: str1_1,str2_2,str3_3

Mark Barinstein
  • 11,456
  • 2
  • 8
  • 16