如何在DB2的存储过程中拆分字符串

how to split a string in stored procedure of DB2

我需要在 DB2 中拆分一个字符串,例如我的字符串是:

2660____,275____,10472316, ...

我需要一个循环来获取所有这些,我知道存储过程 DB2 中存在 FOR,但我不能使用它

我这样写例如:

FOR i AS mycursor CURSOR FOR SELECT SUBSTR(list, 1, LOCATE(',',list)-1) FROM SYSIBM.SYSDUMMY1 do
    ...
END FOR;

但这不起作用。

谢谢

按照指定尝试以下操作 here:

BEGIN
  DECLARE V_VAR VARCHAR (100);

  SET V_VAR = '2660____,275____,10472316';

  FOR C1 AS 
    SELECT TOK.TOKEN
    FROM 
      XMLTABLE
    (
      'for $id in tokenize($s, ",") return <i>{string($id)}</i>' PASSING V_VAR AS "s"
      COLUMNS
        SEQ   FOR ORDINALITY
      , TOKEN VARCHAR(20) PATH '.'
    ) TOK
    ORDER BY TOK.SEQ
  DO
    CALL DBMS_OUTPUT.PUT_LINE (C1.TOKEN);
  END FOR;

END
@