DB2常用函数
DB2分页
/*foo*/ select * from ( select rownumber() over() as rownumber_, * from foos ) as temp_ where rownumber_ between ?+1 and ?
/*foo*/ select * from ( select rownumber() over() as rownumber_, row_.* from ( select distinct * from foos ) as row_ ) as temp_ where rownumber_ between ?+1 and ?
/*foo*/ select * from ( select rownumber() over(order by foo.bar, foo.baz) as rownumber_, * from foos foo order by foo.bar, foo.baz ) as temp_ where rownumber_ between ?+1 and ?
/*foo*/ select * from ( select rownumber() over() as rownumber_, row_.* from ( select distinct * from foos foo order by foo.bar, foo.baz ) as row_ ) as temp_ where rownumber_ between ?+1 and ?
?
语句:
case when expression then ... else ... end;
SELECT Name, Dept, Address..street, Address..number, Address..city,
????? Address..state,
????? CASE
???????? WHEN Address IS OF (US_addr_t)
???????? THEN TREAT(Address AS US_addr_t)..zip
???????? WHEN Address IS OF (Germany_addr_t)
???????? THEN TREAT (Address AS Germany_addr_t)..family_name
???????? WHEN Address IS OF (Brazil_addr_t)
???????? THEN TREAT (Address AS Brazil_addr_t)..neighborhood
????? ELSE NULL END
????? FROM Employee
????? WHERE Salary > 20000;
?
1、类型转化函数:
??转化为数字类型的:
decimal,?double,?Integer,?smallint,real
Hex(arg):转化为参数的16进制表示。
??转化为字符串类型的:
char,?varchar
Digits(arg):返回arg的字符串表示法,arg必须为decimal。
??转化为日期时间的:
date,?time,timestamp
2、时间日期:
year,?quarter,?month,?week,?day,?hour,?minute?,second
dayofyear(arg):返回arg在年内的天值
Dayofweek(arg):返回arg在周内的天值
days(arg):返回日期的整数表示法,从0001-01-01来的天数。?
midnight_seconds(arg):午夜和arg之间的秒数。
Monthname(arg):返回arg的月份名。
Dayname(arg):返回arg的星期。?
3、字符串函数:
length,lcase,?ucase,?ltrim,?rtrim
Coalesce(arg1,arg2….):返回参数集中第一个非null参数。
Concat?(arg1,arg2):连接两个字符串arg1和arg2。
insert(arg1,pos,size,arg2):返回一个,将arg1从pos处删除size个字符,将arg2插入该位置。
left(arg,length):返回arg最左边的length个字符串。
locate(arg1,arg2,<pos>):在arg2中查找arg1第一次出现的位置,指定pos,则从arg2的pos处开始找arg1第一次出现的位置。
posstr(arg1,arg2):返回arg2第一次在arg1中出现的位置。
repeat(arg1?,num_times):返回arg1被重复num_times次的字符串。
replace(arg1,arg2,arg3):将在arg1中的所有arg2替换成arg3。
right(arg,length):返回一个有arg左边length个字节组成的字符串。
space(arg):返回一个包含arg个空格的字符串。
substr(arg1,pos,<length>):返回arg1中pos位置开始的length个字符,如果没指定length,则返回剩余的字符。
4、数学函数:?
Abs,?count,?max,?min,?sum
Ceil(arg):返回大于或等于arg的最小整数。
Floor(arg):返回小于或等于参数的最小整数。
Mod