ESQL for splitting a string into mulitple values

2019-07-22 12: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.

2条回答
成全新的幸福
2楼-- · 2019-07-22 12:52

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.

查看更多
够拽才男人
3楼-- · 2019-07-22 12:59

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&

查看更多
登录 后发表回答