The following articles mainly describe the types of commonly used DB2 functions. I saw the types of commonly used DB2 functions on the relevant website two days ago. I think it is quite good. I will share them with you, the following is a detailed description of the relevant content, hoping to help you in this regard.
DB2 common functions 1. type conversion functions:
- decimal, double, Integer, smallint,real,Hex(arg),
- date, time,timestamp,char, varchar
Common examples:
Convert to string type
- Oracle: select to_char(15.5000) from dual;
- DB2: select char(15.5000) from sysibm.sysdummy1
Converted to date and time
- Oracle: select to_date('2008-01-01','yyyy-mm-dd') from dual;
- DB2: select date('2008-01-01') from sysibm.sysdummy1
DB2 common functions 2. Date and Time:
Year, quarter, month, week, day, hour, minute, second
Dayofyear (arg): returns the Daily Value of arg within the year.
Dayofweek (arg): returns the Daily Value of arg within a week.
Days (arg): returns the integer representation of the date, from-01-01.
Midnight_seconds (arg): the number of seconds between midnight and arg.
Monthname (arg): returns the month name of arg.
Dayname (arg): returns the week of arg.
Common examples:
Returns the current system time.
- Oracle: select sysdate from dual;
- DB2: select current date from sysibm.sysdummy1
Returns the next day of the current time)
- Oracle: select sysdate,sysdate + interval '1' day from dual;
- DB2: select current date + 1 day from sysibm.sysdummy1
DB2 common functions 3. String functions:
- length,lcase, ucase, ltrim, rtrim
Coalesce (arg1, arg2 ....) : The first non-null parameter in the returned parameter set.
Concat (arg1, arg2): connects two strings: arg1 and arg2.
Insert (arg1, pos, size, arg2): returns one. arg1 is deleted from the pos,
Insert arg2 to this location.
Left (arg, length): returns the leftmost length string of arg.
Locate (arg1, arg2, <pos>: Find the location where arg1 first appears in arg2, specify pos,
The first position of arg1 appears at the pos of arg2.
Posstr (arg1, arg2): returns the position where arg2 first appeared in arg1.
Repeat (arg1, num_times): returns the string that arg1 is repeated for num_times.
Replace (arg1, arg2, arg3): replace all arg2 in arg1 with arg3.
Right (arg, length): returns a string consisting of the Left length bytes of arg.
Space (arg): returns a string containing arg spaces.
Substr (arg1, pos, <length>: returns the length starting from the pos position in arg1. If the length is not specified, the remaining characters are returned.