How to split a string value based on a delimiter in DB2

后端 未结 10 1741
失恋的感觉
失恋的感觉 2020-11-27 08:09

How do you split a string value in DB2?

For example, given the value:

CHG-FFH.

I want to split on the dash (-), which would resul

10条回答
  •  长情又很酷
    2020-11-27 08:28

    I needed to use instr, substr, trim, and messed with locate as well.. but instr, and substr are all supported. You can find a pattern. I had to go through a varchar split with ' - ' and needed to find the end and go back from there.

               select  itn, 
               substr(Message, 1 , locate(' - ', Message)) FIRST_SSR,  
               SUBSTR(Message , instr( message, ' - ', octets)+1, (instr( 
                message, '(Ref', octets)+1)) SECOND_STR ,
               Message
                  from
             (
       select p.itn itn, 
              substr(p.msg,  instr( p.msg, ' - ' , octets)+21) Message
        from itnpad p
        where p.msg like '%MR - Multiple Requests%'
    
           ) A 
    

提交回复
热议问题