ITPub博客

首页 > 数据库 > Oracle > oracle sign,greatest,decode,nvl wz

oracle sign,greatest,decode,nvl wz

Oracle 作者:shenqi0420 时间:2010-05-01 11:13:01 0 删除 编辑

oracle
1sign
取数字n的符号,大于0返回1,小于0返回-1,等于0返回0
2greatest( expr1, expr2, ... expr_n )
expr1, expr2, . expr_n 可以值也可以是函数.
函数功能:
  取得值最大值。
3decode(字段或字段的运算,值1,值2,值3)

       这个函数运行的结果是,当字段或字段的运算的值等于值1时,该函数返回值2,否则返回值3
 当然值1,值2,值3也可以是表达式,这个函数使得某些sql语句简单了许多


String sb="select hs_COLLECT_ID,hs_item_type,hs_VO_POSTING_DATE," +
    "(nvl(sum( decode(ds_clin_vo_type,101,ds_clin_amount)),0)+
nvl(sum(decode(ds_clin_vo_type,102,-ds_clin_amount)),0)) as amount from tbl_collect_vrm  where ds_SUPPORT_ID=?" +
    " and (ds_CLIN_VO_TYPE='101' or ds_CLIN_VO_TYPE='102')
 and to_date(hs_vo_posting_date,'YYYY-MM-DD') between (sysdate-?) and
sysdate group by hs_COLLECT_ID,hs_item_type,hs_VO_POSTING_DATE order by hs_vo_posting_date desc,hs_COLLECT_ID asc";
4oracle的nvl函数的用法
通过查询获得某个字段的合计值,如果这个值位null将给出一个预设的默认值
select nvl(sum(t.dwxhl),1) from tb_jhde t where zydm=-1这里关心的nvl的用法,nvl(arg,value)代表如果前面的arg的值为null那么返回的值为后面的value

另一个有关的有用方法
declare
i integer
select nvl(sum(t.dwxhl),1) into i from tb_jhde t where zydm=-1这样就可以把获得的合计值存储到变量i中,如果查询的值为null就把它的值设置为默认的1
select sum(null) from dual

 

<!-- 正文结束 -->

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/22126648/viewspace-1117044/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: 没有了~
下一篇: 没有了~
请登录后发表评论 登录
全部评论

注册时间:2009-07-16