The STRIP environment product of the string scalar function added by DB2 V9: DB2 UDB platform: Linux Unix Windows Version: V9 V9.5 the problem starts from DB2 V9 and a new string scalar function STRIP is added, it is convenient for developers to process strings. Note: To display spaces, use # to indicate the starting and ending positions of strings. in DB2 program development, you may sometimes need to remove spaces or "0" characters before or after a string, for example: the expected string --------- ---------------- #00000999000 #999 #999 #00990090000 #99 #99 9 #99 9 #990090000 # Before DB2 V8.2, developers generally use a combination of REPLACE, LTRIM, and RTRIM. Starting from V9.1, we can use the STRIP function or TRIM function. Here we will briefly introduce the STRIP function. The TRIM function is similar in usage. If you are interested, refer to the DB2 SQL reference manual. The syntax of the STRIP function is as follows:
>-STRIP -- (--- string -- expression -- + -------------------- + ---)-> <'-, -- + -- BOTH ---- + -- + ---- + --- '+ -- LEADING-++ -- L ------- ++ -- TRAILING +'-T --------- 'B: BOTH indicates two ends of L: LEADING: T: TRAILING: strip-character: a single character constant to be truncated
The preceding string is used as an example:
db2 "select '#'||strip('00000999000',b,'0')||'#' from sysibm.sysdummy1" 1 ------------- #999# 1 record(s) selected. db2 "select '#'||strip(' 999 ',t,' ')||'#' from sysibm.sysdummy1" 1 ------------- # 999# 1 record(s) selected. db2 "select '#'||strip(' 99 9 ',t,' ')||'#' from sysibm.sysdummy1" 1 ------------- # 99 9# 1 record(s) selected. db2 "select '#'||strip('00990090000',l,'0')||'#' from sysibm.sysdummy1" 1 ------------- #990090000# 1 record(s) selected.