oracle中nvl函数在mysql里面怎么使用

Oracle中的NVL函数

 

Oracle中函数以前介绍的字符串处理,日期函数,数学函数,以及转换函数等等,还有一类函数是通用函数。主要有:NVL,NVL2,NULLIF,COALESCE,这几个函数用在各个类型上都可以。

下面只介绍介绍nvl函数的用法。

在介绍这个之前你必须明白什么是oracle中的空值null

NVL函数

NVL函数的格式如下:NVL(expr1,expr2)

含义是:如果oracle第一个参数为空那么显示第二个参数的值,如果第一个参数的值不为空,则显示第一个参数本来的值。

 在这里写一个oralce数据库换mysql数据例子:

原来的oralce语句如下:

create or replace view v_ms_reconductplanunvaliable as
(
                (select.........,
            sum(nvl(r.frecnum,0)*nvl(r.ftranRelation,1)) as unvaliableNum
            from.........and.........

            group by ...........

        )
        union all         (
                select...............,
                sum(nvl(r.fapprovenum,0)*nvl(r.ftranRelation,1)) as unvaliableNum
                from.................and.................

                 group by..................

        )
        union all         (
              select .................,
              sum(nvl(r.foutnum,0)*nvl(r.ftranRelation,1)) as unvaliableNum
              from.................. and.............

               group by........................

        )

       );

换成mysql语句如下:

create or replace view v_ms_reconductplanunvaliable as     
        select r.fuseplanid,r.fuseplandetid,r.fmaterialid,r.fbatch,
            sum(IFNULL(r.frecnum,0)*IFNULL(r.ftranRelation,1)) as unvaliableNum
            from .....

            group by .....        
        union all
        
                select ......,
                sum(IFNULL(r.fapprovenum,0)*IFNULL(r.ftranRelation,1)) as unvaliableNum
                from .. and (...)
                 group by .....        
        union all
       
              select .................,
              sum(IFNULL(r.foutnum,0)*IFNULL(r.ftranRelation,1)) as unvaliableNum
              from ...................and t.fuse='' and ..........

              group by .........       
         

去掉前后去掉括号,以适用于union 函数。

 

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值