Split a VARCHAR in DB2 to retrieve a value inside

后端 未结 5 604
我在风中等你
我在风中等你 2020-12-10 06:40

I have a VARCHAR column that contains 5 informations (2 CHAR(3) and 3 TIMESTAMP) separated with \'$\'.

C         


        
5条回答
  •  独厮守ぢ
    2020-12-10 06:49

    If your DB2's version can do it, you can use then LOCATE_IN_STRING function for to found position of your separator. The LOCATE_IN_STRING function returns the starting position of a string and enable you to choice the Nth instance. You can found documentation of this function here

    For your example, you can use this code :

    select 
    substring(col, LOCATE_IN_STRING(col, '$', 1, 3), LOCATE_IN_STRING(col, '$', 1, 4) - LOCATE_IN_STRING(col, '$', 1, 3))                       
    from MYTABLE                                            
    

提交回复
热议问题