标签:
—————常用SQL函数(实例简述)—————
数据库环境:DB2数据库; 执行工具:Toad for DB2
1.转字符串:to_char()
日期类型:to_char(birthday,‘yyyy-mm-dd‘);
整型:to_char(kh_BM);
—————————————————————————————————————
select listagg(abc,‘,‘) from table where rq=‘2016-03-22‘ and departmentid=332;
注:(我的测试环境下,其他数据库环境不确定)转换成列的行数不超过4000,即:The length resulting from "LISTAGG" can not greater than "4000".
—————————————————————————————————————
3.取最大(小)值:max(字段名)/min(字段名)
select max(abc) from table;
—————————————————————————————————————
4.求和:sum(字段名)
select sum(abc) from table;
—————————————————————————————————————
5.值为null则自动赋值:value(字段名,赋值)
select value(abc,0) from able;
注:如果字段abc的查询结果为null,则赋值0;
—————————————————————————————————————
6.转换date类型:to_date (‘日期‘, ‘格式‘)
select value(abc,0) from table where rq=to_date (‘2016-03-22‘, ‘YYYY-MM-dd‘);
—————————————————————————————————————
7.返回参数第一个非null值:COALESCE(字段名,0.00)
select COALESCE(abc,0.00) from able;
—————————————————————————————————————
(未完,不定期更新)
标签:
原文地址:http://www.cnblogs.com/luojun/p/5304970.html