【问题标题】:If empty case in SELECT statement [closed]如果 SELECT 语句中的大小写为空 [关闭]
【发布时间】:2013-06-22 10:36:21
【问题描述】:

我想在 if MOPACTIVITY.MOPSERVICEIMPACTED is = Null 处运行 SELECT 语句,然后使用 MOPACTIVITY.MOPOTHER 字段。

我会将此作为案例陈述吗?语法是什么样的?

【问题讨论】:

    标签: sql oracle select


    【解决方案1】:

    改用合并:

    select coalesce(MOPACTIVITY.MOPSERVICEIMPACTED, MOPACTIVITY.MOPOTHER)
      from ...
    

    您可以使用 CASE 语句来做到这一点:

    select case when MOPACTIVITY.MOPSERVICEIMPACTED is not null then MOPACTIVITY.MOPSERVICEIMPACTED
                else MOPACTIVITY.MOPOTHER
           end
      from ...
    

    【讨论】:

      【解决方案2】:

      您不需要大小写,nvl 就足够了(假设您要检查的列是varchar2):

      select
          nvl(MOPACTIVITY.MOPSERVICEIMPACTED, MOPACTIVITY.MOPOTHER)
          ...
      

      【讨论】:

        【解决方案3】:

        声明@c1 varchar(10)=NULL 当@c1 为空时选择案例然后'asasasas' 否则@c1 结束

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2014-09-25
          • 2017-10-19
          • 1970-01-01
          • 1970-01-01
          • 2015-06-23
          • 2012-05-28
          • 2014-09-23
          • 1970-01-01
          相关资源
          最近更新 更多