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

来源:互联网 发布:烯牛数据工作怎么样 编辑:程序博客网 时间:2024/06/04 20:04

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 函数。

 

0 0