ESQL for splitting a string into mulitple values

て烟熏妆下的殇ゞ 提交于 2019-12-11 02:38:12

问题


Following Input xml field needs to be substringed for 6 characters and each 6 characters should be splitted and saved in the option field of output.

Input: 
<feature>124414500045563879</feature>

output:
<option>124414</option>
<option>500045</option>
<option>563879</option>

Is there any tokenizer function available in IIB ESQL to achieve the above result.


回答1:


As far as I know, no there isn't a String Tokenizer function in ESQL.

But you could use the following procedure as base to achieve your goal. This method splits S on Delim into an array in Env (Environment.Split.Array[]) and removes Environment.Split before refilling it.

In your case, you don't need the Delim, you should work with a fixed length in the Substring part.

CREATE PROCEDURE Split (IN S CHARACTER, IN Env REFERENCE, IN Delim CHARACTER) 
BEGIN 
   DECLARE P INTEGER; 
   DECLARE Idx INTEGER 1; 

   SET Env.Split = NULL; 

   REPEAT 
      SET P = POSITION(Delim IN S); 
      IF P = 0 THEN 
         SET Env.Split.Array[Idx] = S; 
      ELSE 
         SET Env.Split.Array[Idx] = LEFT(S, P - 1); 
         SET S = SUBSTRING(S FROM P + LENGTH(Delim)); 
         SET Idx = Idx + 1; 
      END IF; 
  UNTIL P = 0    
  END REPEAT;    
END;

Source: http://www.mqseries.net/phpBB2/viewtopic.php?p=97845&




回答2:


Another solution could be to take the value of feature as bitstream, build a new BLOB message from it, and have it re-parsed using a message definition that describes the tokens in that value. After the re-parsing, you can further process the new logical message.



来源:https://stackoverflow.com/questions/45348397/esql-for-splitting-a-string-into-mulitple-values

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!