zoukankan      html  css  js  c++  java
  • Oralce 如何将查询结果中的0转成空的

    我们遇到过大多的情况的需求是查询结果中空转为0,这个可以通过oracle的NVL()函数就可以搞定。

    之前做报表客户有个需求,查询出结果为0 要转成空的,不显示0

    那么在oracle有没有现成函数能搞定呢?有的

    1、方法1:NULLIF()函数

    1)介绍

    NULLIF (expr1, expr2),若expr1和expr2相等,返回NULL;不相等,等返回expr1

    2)例子

    --将 0 转成 空 ,结果 空  ---
    select NULLIF('', to_char(0)) SexStr1  from dual;

    结果

    3)实际应用

    -- 将入库通知单的入库数量 将 0 转成 空   ---
    select NULLIF('', to_char(Num))  InNum from Dxc_In_Notice;

    2、方法2:用case when 判断

    1)介绍

        用法就不解释了,跟C#的if else查不多。

    2)例子

    --将 0 转成 空 ,结果 空  ---
    select (case to_char(0) when '1' then '' when '2' then ''else '' end) SexStr2 from dual;

    3)实际应用

    --将 0 转成 空 ,结果 空  ---
    select (case to_char(Sex) when '1' then '' when '2' then ''else '' end) SexStr2 from EdsEmployee;

    注意:NULLIF()  函数的参数类型要一致,case 对象和when对象也一样。

  • 相关阅读:
    bat windows批处理 移动所有子目录文件
    Oracle常见的QA
    [转载]行动起来
    [转载]微笑
    Excel数据更新至Mysql数据库
    sql server QA
    关于SharpZipLib的压缩与解压问题
    整合Spring.net到asp.net网站开发中初探
    设计模式概要
    Oracle 常用语句档案(二)
  • 原文地址:https://www.cnblogs.com/xielong/p/11214787.html
Copyright © 2011-2022 走看看